php-src/Zend/tests/undef_index_to_exception.phpt
Nikita Popov 3c68f38fda Restrict allowed usages of $GLOBALS
This restricts allowed usage of $GLOBALS, with the effect that
plain PHP arrays can no longer contain INDIRECT elements.

RFC: https://wiki.php.net/rfc/restrict_globals_usage

Closes GH-6487.
2021-01-06 12:46:24 +01:00

47 lines
728 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 array key 0
array(0) {
}
Undefined array key "key"
array(0) {
}
Undefined global variable $test
Undefined variable $test