Category
language · php-src-strict · compile-time fatal · $GLOBALS[] append (sibling of closed #32229)
Problem
Appending to $GLOBALS with empty dim ($GLOBALS[] = 1) compiles and runs (rc=0). Zend 8.1+ is a compile-time fatal with a distinct sentence from wholesale assign:
Cannot append to $GLOBALS
#32229 (closed) covered $GLOBALS = [], $GLOBALS += …, and unset($GLOBALS) → $GLOBALS can only be modified using the $GLOBALS[$name] = $value syntax. Indexed $GLOBALS['x'] = 1 is valid on both sides (control). Empty-dim append is a separate zend_compile_assign_dim check and is still accepted here.
Verified 2026-08-18 @ dda76adf48 vs Zend 8.2.32.
| Repro |
Zend 8.2.32 |
VM / JIT |
$GLOBALS[] = 1; echo "accepted"; |
Fatal Cannot append to $GLOBALS (rc=255) |
accepted (rc=0) |
$GLOBALS['x'] = 1; (control) |
rc=0 |
rc=0 |
$GLOBALS = []; (control, #32229) |
Fatal $GLOBALS can only be modified using the $GLOBALS[$name] = $value syntax |
should already match after #32229 |
php-src reference
- php/php-src
Zend/zend_compile.c — zend_compile_assign_dim() when the variable is $GLOBALS and the dim is omitted ([]) → Cannot append to $GLOBALS
- PHP 8.1 “Restrict $GLOBALS” RFC; indexed
$GLOBALS[$name] remains the only legal write; append is never legal
PHP implementation target
Repro
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_globals_append.php 2>&1 | head -5'
./script/docker-exec.sh -- bash -lc 'php bin/jit.php test/repro/maintainer_gap_globals_append.php 2>&1 | head -5'
<?php
$GLOBALS[] = 1;
echo "accepted\n";
Done when
Category
language· php-src-strict · compile-time fatal ·$GLOBALS[]append (sibling of closed #32229)Problem
Appending to
$GLOBALSwith empty dim ($GLOBALS[] = 1) compiles and runs (rc=0). Zend 8.1+ is a compile-time fatal with a distinct sentence from wholesale assign:Cannot append to $GLOBALS
#32229 (closed) covered
$GLOBALS = [],$GLOBALS += …, andunset($GLOBALS)→ $GLOBALS can only be modified using the $GLOBALS[$name] = $value syntax. Indexed$GLOBALS['x'] = 1is valid on both sides (control). Empty-dim append is a separatezend_compile_assign_dimcheck and is still accepted here.Verified 2026-08-18 @
dda76adf48vs Zend 8.2.32.$GLOBALS[] = 1; echo "accepted";$GLOBALS['x'] = 1;(control)$GLOBALS = [];(control, #32229)php-src reference
Zend/zend_compile.c—zend_compile_assign_dim()when the variable is$GLOBALSand the dim is omitted ([]) → Cannot append to $GLOBALS$GLOBALS[$name]remains the only legal write; append is never legalPHP implementation target
lib/Compiler.php— next torejectGlobalsReferenceAcquisition()(Language: $ref = &$GLOBALS must compile-time fatal — VM executes (Zend/zend_compile.c) #15627) / Language: $GLOBALS = [] compiles — Zend can only be modified using $GLOBALS[$name] syntax (Zend/zend_compile.c) #32229 assign/unset: when compiling dim-assign/append, if the base name isGLOBALSand the dim is empty/null,throwCompileError('Cannot append to $GLOBALS')$GLOBALS[$name]” string — Zend’s append diagnostic is differentruntime/*.clogicRepro
Done when
Cannot append to $GLOBALS(never printaccepted)$GLOBALS['x'] = 1still succeeds;#32229assign/+=/unset($GLOBALS)messages unchanged.phptguard undertest/compliance/cases/language/