You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Language: static::/self::/parent:: method call in function compiles — Zend Cannot use "static" when no class scope is active (Zend/zend_compile.c) #32227
language · php-src-strict · compile-time fatal · self/parent/static (not #29096)
Problem
A function (no class scope) that contains static::foo(), self::foo(), or parent::foo()compiles and runs to accepted if the function is never called. Zend is a compile-time fatal even when f() is unused:
Cannot use "static" when no class scope is active (same for self / parent).
If f()is invoked, VM/JIT then throw a runtime Error (Cannot access "static" when no class scope is active). Zend never reaches runtime — the file does not compile. That is a silent-accept of an illegal program (rc=0 vs 255).
#29096 (closed) was eval at top level: runtime message wording (Cannot use … in the global scope vs Zend Cannot access …). Distinct: here the method-call form is not rejected at compile at all. static::class / self::class in a function already compile-abort on VM (wording still #29096-shaped).
Verified 2026-08-18 @ 3633ba3bb9 vs Zend 8.2.32.
Repro
Zend 8.2.32
VM / JIT
function f() { static::foo(); } echo "accepted";
Fatal Cannot use "static" when no class scope is active
accepted (rc=0)
function f() { self::foo(); } echo "accepted";
Fatal Cannot use "self" when no class scope is active
accepted (rc=0)
function f() { parent::foo(); } echo "accepted";
Fatal Cannot use "parent" when no class scope is active
accepted (rc=0)
function f() { echo static::class; } (control)
same Zend fatal
VM already compile-aborts (message: global scope)
php-src reference
php/php-src Zend/zend_compile.c — zend_compile_class_ref() / ZEND_FETCH_CLASS_SELF|PARENT|STATIC with !CG(active_class_entry) → Cannot use "%s" when no class scope is active
PHP implementation target
lib/Compiler.phpcompileStaticCallOpcodes() / class-ref lowering — if the fetch class is the self/parent/static keyword and there is no active class entry, throwCompileError with Zend’s Cannot use "…" when no class scope is active
VM and JIT compile-abort with Zend substring Cannot use "static" when no class scope is active (never print accepted); same for self and parent method-call forms
Invoking f() is unnecessary — fatal is at compile, matching Zend
static::class / self::class in a function still compile-abort (prefer Zend “no class scope is active” wording)
Compliance .phpt guard under test/compliance/cases/language/
Category
language· php-src-strict · compile-time fatal ·self/parent/static(not #29096)Problem
A function (no class scope) that contains
static::foo(),self::foo(), orparent::foo()compiles and runs toacceptedif the function is never called. Zend is a compile-time fatal even whenf()is unused:Cannot use "static" when no class scope is active (same for
self/parent).If
f()is invoked, VM/JIT then throw a runtime Error (Cannot access "static" when no class scope is active). Zend never reaches runtime — the file does not compile. That is a silent-accept of an illegal program (rc=0 vs 255).#29096 (closed) was eval at top level: runtime message wording (
Cannot use … in the global scopevs ZendCannot access …). Distinct: here the method-call form is not rejected at compile at all.static::class/self::classin a function already compile-abort on VM (wording still#29096-shaped).Verified 2026-08-18 @
3633ba3bb9vs Zend 8.2.32.function f() { static::foo(); } echo "accepted";function f() { self::foo(); } echo "accepted";function f() { parent::foo(); } echo "accepted";function f() { echo static::class; }(control)php-src reference
Zend/zend_compile.c—zend_compile_class_ref()/ZEND_FETCH_CLASS_SELF|PARENT|STATICwith!CG(active_class_entry)→ Cannot use "%s" when no class scope is activePHP implementation target
lib/Compiler.phpcompileStaticCallOpcodes()/ class-ref lowering — if the fetch class is theself/parent/statickeyword and there is no active class entry,throwCompileErrorwith Zend’s Cannot use "…" when no class scope is activelib/Compiler/PseudoClassTypeHintCompileCheck.phpmessage helper (messageFor()) which already has the Zend compile string (Language: static return type outside class — compile accepts, Zend parse fatal (Zend/zend_compile.c) #17480 type-hint path)runtime/*.clogicRepro
Done when
Cannot use "static" when no class scope is active(never printaccepted); same forselfandparentmethod-call formsf()is unnecessary — fatal is at compile, matching Zendstatic::class/self::classin a function still compile-abort (prefer Zend “no class scope is active” wording).phptguard undertest/compliance/cases/language/