On 04/01/2015 09:15 AM, Dan Ackroyd wrote:
> Hi,
> 
> I'd like to get people's feedback for the idea of making setlocale be
> either deprecated and to be removed eventually or just increasing the
> warning level against people using it.
> 
> The short version of why we should do this is that setlocale breaks
> things. It is a process wide operation, that is not thread safe on
> most platforms. Although people use it to alter the way strings are
> output, it also breaks libraries that are assuming that they are
> running in a "C" locale.

The PHP setlocale() wrapper can be made threadsafe in a portable manner
via newlocale()/uselocale(), so that part isn't an issue. Someone just
needs to write the code for the threaded SAPIs. It hasn't been a high
priority due to how few people use non-Windows ZTS mode so far.

Obviously within the same process there may be issues with changing a
locale to something unexpected by subsequent code, but that is really a
bug in that code then. If some library function expects and only works
in the "C" locale, it should make sure it is in that locale before doing
anything and then restoring the locale back appropriately. And with a
bit of symbol trickery libraries that do actually call setlocale to
change it and restore it can be made to use our newlocale/uselocale
thread-local locale mechanism.

setlocale() is used quite a bit and for non-threaded, which is the bulk
of php usage, it tends to work quite well. It is annoying that it is
process-wide and as you noted that can cause issues, sure, and that the
current implementation isn't threadsafe, but it isn't something that is
technically unsolvable. Rather than throwing our hands in the air and
just pulling the rug out from under people using it, we should take a
look at fixing the problems associated with it instead.

-Rasmus

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to