Changes to string handling
Strings containing hexadecimal numbers are no longer considered to be numeric. For example:
Hexadecimal strings are no longer considered numeric
Strings containing hexadecimal numbers are no longer considered to be numeric. For example:
<?php
var_dump("0x123" == "291");
var_dump(is_numeric("0x123"));
var_dump("0xe" + "0x1");
var_dump(substr("foo", "0x1"));
?>5
bool(true)
bool(true)
int(15)
string(2) "oo"7
bool(false)
bool(false)
int(0)
Notice: A non well formed numeric value encountered in /tmp/test.php on line 5
string(3) "foo"filter_var() can be used to check if a string contains a hexadecimal number, and also to convert a string of that type to an int:
<?php
$str = "0xffff";
$int = filter_var($str, FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_HEX);
if (false === $int) {
throw new Exception("Invalid integer!");
}
var_dump($int); // int(65535)
?>\u{ may cause errors
Due to the addition of the new Unicode codepoint escape syntax, strings containing a literal \u{ followed by an invalid sequence will cause a fatal error. To avoid this, the leading backslash should be escaped.