Skip to content

Language: new static/self/parent in function compiles — Zend Cannot use "static" when no class scope is active (re-#32227, Zend/zend_compile.c) #32252

Description

@PurHur

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

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