Taking advantage of locale independence
In versions of PHP prior to PHP 8, several string functions and operations were tied to the locale. The net effect was that numbers were internally stored differently depending on the locale. This practice introduced subtle inconsistencies that were extremely difficult to detect. After reviewing the material presented in this chapter, you will be in a better position to detect potential application code changes following a PHP 8 upgrade, thereby avoiding application failure.
Understanding the problems associated with locale dependence
The unfortunate side effect of locale dependence in earlier PHP versions was inconsistent results when typecasting from float
to string
and then back again. Inconsistencies were also seen when a float
value was concatenated to a string
. Certain optimizing operations performed by OpCache resulted in the concatenation operation occurring before the locale had been set, yet another way in which inconsistent results...