mirror of
https://github.com/php/php-src.git
synced 2024-12-02 22:34:55 +08:00
220880ad2d
When performing an RW modification of an array offset, the undefined offset warning may call an error handler / OB callback, which may destroy the array we're supposed to change. Detect this by temporarily incrementing the reference count. If we find that the array has been modified/destroyed in the meantime, we do nothing -- the execution model here would be that the modification has happened on the destroyed version of the array.
47 lines
711 B
PHP
47 lines
711 B
PHP
--TEST--
|
|
Converting undefined index/offset notice to exception
|
|
--FILE--
|
|
<?php
|
|
|
|
set_error_handler(function($_, $msg) {
|
|
throw new Exception($msg);
|
|
});
|
|
|
|
$test = [];
|
|
try {
|
|
$test[0] .= "xyz";
|
|
} catch (Exception $e) {
|
|
echo $e->getMessage(), "\n";
|
|
}
|
|
var_dump($test);
|
|
|
|
try {
|
|
$test["key"] .= "xyz";
|
|
} catch (Exception $e) {
|
|
echo $e->getMessage(), "\n";
|
|
}
|
|
var_dump($test);
|
|
|
|
unset($test);
|
|
try {
|
|
$GLOBALS["test"] .= "xyz";
|
|
} catch (Exception $e) {
|
|
echo $e->getMessage(), "\n";
|
|
}
|
|
try {
|
|
var_dump($test);
|
|
} catch (Exception $e) {
|
|
echo $e->getMessage(), "\n";
|
|
}
|
|
|
|
?>
|
|
--EXPECT--
|
|
Undefined offset: 0
|
|
array(0) {
|
|
}
|
|
Undefined index: key
|
|
array(0) {
|
|
}
|
|
Undefined index: test
|
|
Undefined variable: test
|