Well, I was also curious, so I designed the test.
At first I tested setlocale()
with these two files:
<?php
and
<?php
Then I performed them on two separate tabs. First, locale1.php
, which sleeps for 10 seconds after setting the locale, giving us time to run locale2.php
in the meantime.
To my surprise, locale2.php
does not even allow you to change the locale correctly. It appears that sleep( 10 )
in locale1.php
captures the Apache / PHP process in such a way that it does not allow locale2.php
to change the locale. However, it nonetheless repeats the date, but is not localized as you expected.
Edit: Sorry, do it. It appears that locale2.php
changes the locale and locale1.php
and then prints the English date instead of Dutch after sleep. So it looks like it matches the expected behavior from setlocale()
. / Edit
Then I tested IntlDateFormatter
with these two files:
<?php
and
<?php
and then run them again on two separate tabs, as in the first set of files. This gives the expected results: while locale1.php
falls off, locale2.php
beautifully prints the date in US-English in accordance with American rules, after which locale1.php
beautifully prints the date in Dutch according to Dutch rules.
So, concluding, it seems that Intl
safe from this setlocale
problem.
But also reason is Hyunming Kim's answer . I could not comment on this due to the lack of experience using Intl
. I just discovered Intl
.
source share