mirror of
https://github.com/php/php-src.git
synced 2024-12-17 13:59:28 +08:00
b2248789ed
RFC: https://wiki.php.net/rfc/saner-numeric-strings This removes the -1 allow_error mode from is_numeric_string functions and replaces it by a trailing boolean out argument to preserve BC in a couple of places. Most of the changes can be resumed to "numeric" strings which emitted a E_NOTICE now emit a E_WARNING and "numeric" strings which emitted a E_WARNING now throw a TypeError. This mostly affects: - String offsets - Arithmetic operations - Bitwise operations Closes GH-5762
73 lines
1.4 KiB
PHP
73 lines
1.4 KiB
PHP
--TEST--
|
|
Using different sorts of numerical strings as a string offset
|
|
--FILE--
|
|
<?php
|
|
|
|
$str = "The world is fun";
|
|
|
|
$keys = [
|
|
"7",
|
|
"7.5",
|
|
" 7",
|
|
" 7.5",
|
|
" 7 ",
|
|
" 7.5 ",
|
|
"7 ",
|
|
"7.5 ",
|
|
"7str",
|
|
"7.5str",
|
|
" 7str",
|
|
" 7.5str",
|
|
" 7 str",
|
|
" 7.5 str",
|
|
"7 str",
|
|
"7.5 str",
|
|
"0xC",
|
|
"0b10",
|
|
"07",
|
|
];
|
|
|
|
foreach ($keys as $key) {
|
|
try {
|
|
var_dump($str[$key]);
|
|
} catch (\TypeError $e) {
|
|
echo $e->getMessage() . \PHP_EOL;
|
|
}
|
|
}
|
|
|
|
echo "Done\n";
|
|
?>
|
|
--EXPECTF--
|
|
string(1) "l"
|
|
Cannot access offset of type string on string
|
|
string(1) "l"
|
|
Cannot access offset of type string on string
|
|
string(1) "l"
|
|
Cannot access offset of type string on string
|
|
string(1) "l"
|
|
Cannot access offset of type string on string
|
|
|
|
Warning: Illegal string offset "7str" in %s on line %d
|
|
string(1) "l"
|
|
Cannot access offset of type string on string
|
|
|
|
Warning: Illegal string offset " 7str" in %s on line %d
|
|
string(1) "l"
|
|
Cannot access offset of type string on string
|
|
|
|
Warning: Illegal string offset " 7 str" in %s on line %d
|
|
string(1) "l"
|
|
Cannot access offset of type string on string
|
|
|
|
Warning: Illegal string offset "7 str" in %s on line %d
|
|
string(1) "l"
|
|
Cannot access offset of type string on string
|
|
|
|
Warning: Illegal string offset "0xC" in %s on line %d
|
|
string(1) "T"
|
|
|
|
Warning: Illegal string offset "0b10" in %s on line %d
|
|
string(1) "T"
|
|
string(1) "l"
|
|
Done
|