diff --git a/language/types/numeric-strings.xml b/language/types/numeric-strings.xml index 2aadf65287e4..6f14313c2935 100644 --- a/language/types/numeric-strings.xml +++ b/language/types/numeric-strings.xml @@ -31,22 +31,33 @@ NUM_STRING ({INT_NUM_STRING} | {FLOAT_NUM_STRING}) any characters. - + Any string that contains the letter E (case insensitive) bounded by numbers will be seen as a number expressed in scientific notation. - This can produce unexpected results. + This can produce unexpected results, particularly when the significand + (the part of the number before the E) is 0. + To avoid problems in comparisons, strings should usually be compared using + the identity operator (===) or string comparison functions + like strcmp and hash_compare. ]]> - + Strings used in numeric contexts diff --git a/language/types/type-juggling.xml b/language/types/type-juggling.xml index df10696d4e46..75920e8a494d 100644 --- a/language/types/type-juggling.xml +++ b/language/types/type-juggling.xml @@ -84,6 +84,23 @@ If the value cannot be interpreted a TypeError is thrown. Prior to PHP 7.4.0, an E_RECOVERABLE_ERROR was raised. + + + + When using the comparison + operator (==), + numeric strings + will be compared as numbers instead of as strings. + This means that "123" == " 123 " is &true;, + but also that "0e1234" == "0e5678" is &true;, + which can cause unexpected behavior when comparing hexidecimal strings + like those from hash. + The identity operator (===) or a string comparison + function, such as strcmp or + hash_compare, should be used to avoid unexpected + results. + +