# php gettext bindtextdomain behavior

- Thread: https://externals.io/message/50108
- Original archive: https://news-web.php.net/php.internals/50108
- Started by Gerry Reno on 2010-11-05T20:06:03+00:00
- Messages: 9
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #50108 — Gerry Reno — 2010-11-05T20:06:03+00:00

URL: https://externals.io/message/50108#50108

In PHP 5.2.4 (my version) the gettext bindtextdomain function is not 
returning the existing directory settings when the directory argument is 
NULL.
That is the expected behavior for bindtextdomain with GNU and it works 
this way elsewhere such as in python.

PYTHON EXAMPLE:
bindtextdomain("messages", "./locale");
textdomain("messages");

print bindtextdomain("messages",None);
print textdomain(None);

ACTUAL: (correct)
# python test.py
./locale
messages


With PHP what happens is that is just returns the current directory 
rather than the existing bindtextdomain directory setting.

PHP EXAMPLE:
bindtextdomain("messages", "./locale");
textdomain("messages");

print bindtextdomain("messages",NULL)."\n";
print textdomain(NULL)."\n";

ACTUAL: (incorrect)
# php test.php
/var/www/htdocs
messages

EXPECTED:
# php test.php
./locale
messages

Can PHP gettext bindtextdomain be fixed to correctly return the existing 
setting when called with a `NULL` directory argument?

I was not sure if this was a bug so I thought I would present the issue 
on the internal list first.

---

## #50114 — Antony Dovgal — 2010-11-06T20:49:55+00:00

URL: https://externals.io/message/50108#50114 · In reply to: #50108

> In PHP 5.2.4 (my version) the gettext bindtextdomain function is not 
> returning the existing directory settings when the directory argument is 
> NULL.
> That is the expected behavior for bindtextdomain with GNU and it works 
> this way elsewhere such as in python.

> With PHP what happens is that is just returns the current directory 
> rather than the existing bindtextdomain directory setting.
> 
> PHP EXAMPLE:
> bindtextdomain("messages", "./locale");
> textdomain("messages");
> 
> print bindtextdomain("messages",NULL)."\n";
> print textdomain(NULL)."\n";
> 
> ACTUAL: (incorrect)
> # php test.php
> /var/www/htdocs
> messages
> 
> EXPECTED:
> # php test.php
> ./locale
> messages
> 
> Can PHP gettext bindtextdomain be fixed to correctly return the existing 
> setting when called with a `NULL` directory argument?

PHP of course just calls GNU `textdomain()` and you see the result the original function returns, 
not some PHP-specific result.
And no, I cannot reproduce this with PHP 5.3.4-dev or PHP 5.2.15-dev.
You might want to update your PHP and try again.

If you're still able to reproduce it - make sure the problem doesn't appear 
to be in some distro-specific patch, i.e. get the original source tarball 
from php.net and check if the problem actually exists there.
After that you're welcome to fill a bug-report.

-- 
Wbr,
Antony Dovgal
---
http://pinba.org - realtime statistics for PHP

---

## #50116 — Gerry Reno — 2010-11-06T21:34:42+00:00

URL: https://externals.io/message/50108#50116 · In reply to: #50114

> 
>    
> > […]
>    
> > […]
> PHP of course just calls GNU `textdomain()` and you see the result the original function returns,
> not some PHP-specific result.
> And no, I cannot reproduce this with PHP 5.3.4-dev or PHP 5.2.15-dev.
> You might want to update your PHP and try again.
>
> If you're still able to reproduce it - make sure the problem doesn't appear
> to be in some distro-specific patch, i.e. get the original source tarball
> from php.net and check if the problem actually exists there.
> After that you're welcome to fill a bug-report.
>
>    
The function 'textdomain' is not the problem.  It is 'bindtextdomain' 
that has the problem.
I tried this on a newer PHP 5.3.2 installation and it has the exact same 
problem.

root@grp-01-23-02:/tmp# php --version
PHP 5.3.2-1ubuntu4.5 with Suhosin-Patch (cli) (built: Sep 17 2010 13:49:46)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

root@grp-01-23-02:/tmp# cat test.php
<?php

bindtextdomain("messages", "./locale");
textdomain("messages");

print bindtextdomain("messages",NULL)."\n";
print textdomain(NULL)."\n";

?>

root@grp-01-23-02:/tmp# php test.php
/tmp
messages

The correct output should have been:
./locale
messages

---

## #50118 — jeanseb@au-fil-du.net — 2010-11-07T11:14:27+00:00

URL: https://externals.io/message/50108#50118 · In reply to: #50108

Le 05/11/2010 21:06, Gerry Reno a écrit :
> In PHP 5.2.4 (my version) the gettext bindtextdomain function is not
> returning the existing directory settings when the directory argument
> is NULL.
> That is the expected behavior for bindtextdomain with GNU and it works
> this way elsewhere such as in python.
>
> [...]
>
> Can PHP gettext bindtextdomain be fixed to correctly return the
> existing setting when called with a `NULL` directory argument?
>
> I was not sure if this was a bug so I thought I would present the
> issue on the internal list first.

I filled a bug-report with a patch.

But my patch introduce a BC (see my non regression test :
ext/gettext/tests/gettext_bindtextdomain-nulldir.phpt)

http://bugs.php.net/bug.php?id=53251

-- 
Jean-Sébastien H.
Au-Fil-Du.Net

---

## #50119 — Gerry Reno — 2010-11-07T13:57:41+00:00

URL: https://externals.io/message/50108#50119 · In reply to: #50118

> Le 05/11/2010 21:06, Gerry Reno a écrit :
>    
> > […]
> I filled a bug-report with a patch.
>
> But my patch introduce a BC (see my non regression test :
> ext/gettext/tests/gettext_bindtextdomain-nulldir.phpt)
>
> http://bugs.php.net/bug.php?id=53251
>
>    

Thanks for filing the bug.  I reviewed the patch and it does not seem to 
do what is necessary.  What it needs to do is to go get the current 
setting from the previous bindtextdomain call.  This means that 
'bindtextdomain' needs to store the current setting so that it can be 
retrieved later by a call with a `NULL` directory argument.

---

## #50120 — Gerry Reno — 2010-11-07T14:57:47+00:00

URL: https://externals.io/message/50108#50120 · In reply to: #50119

> 
> > […]
>
> Thanks for filing the bug.  I reviewed the patch and it does not seem 
> to do what is necessary.  What it needs to do is to go get the current 
> setting from the previous bindtextdomain call.  This means that 
> 'bindtextdomain' needs to store the current setting so that it can be 
> retrieved later by a call with a `NULL` directory argument.
>
>
>

I added some comments and clarifications on the bindtextdomain problem 
into the bug http://bugs.php.net/bug.php?id=53251

---

## #50373 — jeanseb@au-fil-du.net — 2010-11-18T21:24:18+00:00

URL: https://externals.io/message/50108#50373 · In reply to: #50120

Hi,

Any feedback on this patch ?

http://bugs.php.net/bug.php?id=53251

Regards,

Le 07/11/2010 15:57, Gerry Reno a écrit :
> 
> > […]
>
> I added some comments and clarifications on the bindtextdomain problem
> into the bug http://bugs.php.net/bug.php?id=53251
>

-- 
Jean-Sébastien H.
Au-Fil-Du.Net

---

## #50374 — Gerry Reno — 2010-11-18T22:06:10+00:00

URL: https://externals.io/message/50108#50374 · In reply to: #50373

I put my comments and some clarifications about the patch into the bug.

-Gerry



> Hi,
>
> Any feedback on this patch ?
>
> http://bugs.php.net/bug.php?id=53251
>
> Regards,
>
> Le 07/11/2010 15:57, Gerry Reno a écrit :
>    
> > […]

---

## #50418 — Gerry Reno — 2010-11-23T01:56:41+00:00

URL: https://externals.io/message/50108#50418 · In reply to: #50374

bindtextdomain is badly broken in PHP.  It is not implemented the same 
as the standard GNU implementation or any of the other language 
implementations such as python for example.  And it has crippled the 
ability to do nested access to different gettext translation stores 
because you cannot query for the current setting.   As far as backward 
compatibility, I would not worry about it, because I doubt anyone would 
be relying on retrieving the current setting especially once they found 
out it was absolutely incorrect.

The patch needs updated to correctly fix the problem as I've explained 
in the bug.  I have not seen any activity on this bug recently and this 
needs to get into 5.2.15 and 5.3.3 as soon as possible so that PHP has a 
correct implementation of bindtextdomain.

-Gerry




> I put my comments and some clarifications about the patch into the bug.
>
> -Gerry
>
>
> 
> > […]
