Description
bind_textdomain_codeset()
is documented to return a string on success, and false
on failure. But there is one success case that also returns false
. If you query the codeset for a domain that has not been explicitly set (yet), you will also get false
:
php > var_dump(bind_textdomain_codeset("foo", NULL));
bool(false)
This is because the C function returns NULL
to indicate that the locale's codeset will be used. Quoting from https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/bind_textdomain_codeset.html
If codeset is a null pointer and domainname is a non-empty string,
bind_textdomain_codeset()
shall return the current codeset for the named domain, or a null pointer if a codeset has not yet been set.
I bring this up because musl only supports UTF-8, and always returns NULL
from its bind_textdomain_codeset()
. Its PHP counterpart therefore always appears to fail, when it is working as... well, not quite expected, but as documented.
To summarize:
false
will also be returned if no codeset has been explicitly set for the domain- this function always returns
false
under musl libc where the only supported codeset is UTF-8