Undefined variable variable $GLOBALS
Description
The following code:
<?php
$variable = 'GLOBALS';
$GLOBALS['GLOBALS'] = 'value';
var_dump($GLOBALS);
https://3v4l.org/lpfq6
Resulted in this output:
array(8) {
["_GET"]=>
array(0) {
}
["_POST"]=>
...
}
But I expected this output instead:
string(5) "value"
The global variable GLOBALS shouldn't be allowed because it's hidden behind the superglobal.
Another problem with this superglobal:
Calling $variable = 'GLOBALS';$$variable; outputs Warning: Undefined variable $GLOBALS, but that's not what the user expects, because $GLOBALS is available. I know it's stated in documentation that superglobal array is not allowed, but this error message could be less confusing.
https://www.php.net/manual/en/language.variables.variable.php
PHP Version
PHP 8.4
Operating System
No response
As of PHP 8.1, $GLOBALS is not a real variable (so cannot be referenced through variable variables) and it cannot be used to modify variables (as it provides read-only access to the symbol table).
The latter is already documented. The former doesn't appear to be.