Locales are stupid
Posted
#6153
(In Topic #1294)
Code (PHP)
<?php
setlocale(LC_ALL, 'tr_TR');
echo strtoupper('i');
echo strtolower('I');
var_dump(preg_match('#TIMMY#i', 'timmy') > 0);
setlocale(LC_ALL, 'tr_TR');
echo strtoupper('i');
echo strtolower('I');
var_dump(preg_match('#TIMMY#i', 'timmy') > 0);
You'd expect it to output Iibool(true).
However, if the Turkish locale is actually installed on a server, you get ��bool(false).
This is because the basic letters 'i' and 'I' don't have the same case conversion in Turkish, and everything is following locale rules.
I'm trying to deal with most of this in v11. It seems a small issue, because you can just turn off case conversion locales for Turkish and nobody is going to really be bothered, case conversion is almost entirely used for coding logic rather than display logic.
However, the real kicker is that locale settings are implemented on a per-process level, and if anyone has PHP installed via the Apache module rather than CGI, any other parallel running request on the server may change the locale during your request and screw it up. Imagine you're on a shared server alongside a Turkish website.
For this reason, the Health Check system in v11 is going to give a warning if a server is using the PHP Apache module.
0 guests and 0 members have recently viewed this.
