Category
language · php-src-strict · compile-time fatal · new self / new parent / new static (sibling of closed #32227)
Problem
A function (no class scope) that contains new static, new self, or new parent compiles and prints 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).
#32227 (closed) covered static::foo() method-call form via rejectPseudoClassFetchOutsideKnownClassScope(). new lowering (Op\Expr\New_) never calls that helper, so the same illegal program still loads.
Verified 2026-08-18 @ dda76adf48 vs Zend 8.2.32.
| Repro |
Zend 8.2.32 |
VM / JIT |
function f() { return new static; } echo "accepted"; |
Fatal Cannot use "static" when no class scope is active |
accepted (rc=0) |
function f() { return new self; } |
Fatal Cannot use "self" when no class scope is active |
accepted (rc=0) |
function f() { return new parent; } |
Fatal Cannot use "parent" when no class scope is active |
accepted (rc=0) |
function f() { static::foo(); } (control, #32227) |
same Zend fatal |
VM already compile-aborts |
php-src reference
- php/php-src
Zend/zend_compile.c — zend_compile_new() → zend_ensure_valid_class_fetch_type() / ZEND_FETCH_CLASS_SELF|PARENT|STATIC with !CG(active_class_entry) → Cannot use "%s" when no class scope is active
PHP implementation target
Repro
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_new_static_no_scope.php 2>&1 | head -5'
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_new_self_no_scope.php 2>&1 | head -5'
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_new_parent_no_scope.php 2>&1 | head -5'
./script/docker-exec.sh -- bash -lc 'php bin/jit.php test/repro/maintainer_gap_new_static_no_scope.php 2>&1 | head -5'
<?php
function f() {
return new static;
}
echo "accepted\n";
Done when
Category
language· php-src-strict · compile-time fatal ·new self/new parent/new static(sibling of closed #32227)Problem
A function (no class scope) that contains
new static,new self, ornew parentcompiles and printsacceptedif 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).#32227 (closed) covered
static::foo()method-call form viarejectPseudoClassFetchOutsideKnownClassScope().newlowering (Op\Expr\New_) never calls that helper, so the same illegal program still loads.Verified 2026-08-18 @
dda76adf48vs Zend 8.2.32.function f() { return new static; } echo "accepted";function f() { return new self; }function f() { return new parent; }function f() { static::foo(); }(control, #32227)php-src reference
Zend/zend_compile.c—zend_compile_new()→zend_ensure_valid_class_fetch_type()/ZEND_FETCH_CLASS_SELF|PARENT|STATICwith!CG(active_class_entry)→ Cannot use "%s" when no class scope is activePHP implementation target
lib/Compiler.phpOp\Expr\New_::classbranch (~line 14792) andcompileNewExprForThrow()— before emittingTYPE_NEW, call existingrejectPseudoClassFetchOutsideKnownClassScope()/rejectPseudoClassFetchOutsideKnownClassScopewith the class operand keyword (self/parent/static)compileScopeKnowsNoClassEntry()+PseudoClassTypeHintCompileCheck::messageFor()from Language: static::/self::/parent:: method call in function compiles — Zend Cannot use "static" when no class scope is active (Zend/zend_compile.c) #32227runtime/*.clogicRepro
Done when
Cannot use "static" when no class scope is active(never printaccepted); same fornew selfandnew parentf()is unnecessary — fatal is at compile, matching Zend.phptguard undertest/compliance/cases/language/