php-src/Zend/tests/bug71572.phpt
George Peter Banyard bfe3f934a3 Add warning and convert to exception in string offset assignment:
Convert the empty string assignment to an Error as per RFC [1]
Add a warning that only the first byte will be assigned to the offset if provided
a needle that is longer than one byte.

[1] https://wiki.php.net/rfc/engine_warnings
2020-01-07 21:54:42 +01:00

35 lines
742 B
PHP

--TEST--
Bug #71572: String offset assignment from an empty string inserts null byte
--FILE--
<?php
$str = "abc";
try {
var_dump($str[0] = "");
} catch (\Error $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
var_dump($str[1] = "");
} catch (\Error $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
var_dump($str[3] = "");
} catch (\Error $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
var_dump($str[10] = "");
} catch (\Error $e) {
echo $e->getMessage() . \PHP_EOL;
}
var_dump($str);
?>
--EXPECT--
Cannot assign an empty string to a string offset
Cannot assign an empty string to a string offset
Cannot assign an empty string to a string offset
Cannot assign an empty string to a string offset
string(3) "abc"