Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scope of setlocale function?

Tags:

php

I want to sort an array in php which contains german 'umlaute'. This does not seem to be an easy task for php. I found the following example on the web:

$oldLocale=setlocale(LC_COLLATE, "0");
setlocale(LC_COLLATE, 'de_DE.utf8');
usort($countrys, 'strcoll'); 
setlocale(LC_COLLATE, $oldLocale);

This is working as expected. My question now is, what is the scope of setlocale? Is it limited to the current function I am in, is it limited to my thread, my session or is it global?

I am afraid of creating race conditions, but I cannot find any other information on this than:

The setlocale() function sets locale information.


1 Answers

It will be a global setting, it keeps set the last value while the script is running. It's not related to sessions, it's scope is the php process itself.

http://php.net/manual/en/function.setlocale.php

like image 99
SalDev Avatar answered Dec 04 '25 07:12

SalDev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!