Skip to content

Language: $GLOBALS[] = compiles — Zend Cannot append to $GLOBALS (re-#32229, Zend/zend_compile.c) #32253

Description

@PurHur

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.czend_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

  • VM and JIT compile-abort with Zend substring Cannot append to $GLOBALS (never print accepted)
  • $GLOBALS['x'] = 1 still succeeds; #32229 assign/+=/unset($GLOBALS) messages unchanged
  • Compliance .phpt guard under test/compliance/cases/language/
  • php-src-strict; no php-compiler-strict shortcut

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITarea:vmVirtual machinebugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions