Cannot append to $GLOBALS
Description
$GLOBALS is not a regular array: each of its entries is really a reference to a variable in the global scope, identified by its name. Appending with the empty-bracket operator, which would normally pick the next integer key, has no matching global variable to bind to, so PHP 8.1 turned this previously-meaningless operation into a compile-time error instead of silently creating a global variable literally named “0”.
Example
<?php
$GLOBALS[] = 'value';
?>
Alternatives
- Assign to an explicit, named key instead: $GLOBALS[‘name’] = ‘value’;
Related error messages
Changed Behavior
This error may appear following an evolution in behavior, in previous versions. See GLOBALSAppend