Skip to content

Language: self/parent outside class — "Cannot use … in the global scope" vs Zend "Cannot access … when no class scope is active" (Zend/zend_execute.c) #29096

Description

@PurHur

Category

Language · php-src-strict · scope resolution Error message

Problem

self:: / parent:: evaluated with no active class scope (e.g. eval('self::foo();') at top level) must Error with Zend’s wording. VM already matches for static::, but self/parent use a different string.

Verified 2026-08-08 @ 4bbede110e vs php:8.4-cli 8.4.24.

Repro Zend 8.4.24 VM PROFILE=8.4
eval('self::foo();') Cannot access "self" when no class scope is active Cannot use "self" in the global scope
eval('parent::foo();') Cannot access "parent" when no class scope is active Cannot use "parent" in the global scope
eval('static::foo();') (control) Cannot access "static" when no class scope is active same ✅

php-src reference

PHP implementation target

  • Scope-resolution Error construction in lib/ / VM — align self/parent messages with the existing static path (Zend “Cannot access … when no class scope is active”)
  • PHP-in-PHP only

Repro

./script/docker-exec.sh -- bash -lc 'cat > /tmp/self_parent_scope.php <<'"'"'PHP'"'"'
<?php
try { eval("self::foo();"); } catch (Throwable $e) { echo "self:", $e->getMessage(), "\n"; }
try { eval("parent::foo();"); } catch (Throwable $e) { echo "parent:", $e->getMessage(), "\n"; }
try { eval("static::foo();"); } catch (Throwable $e) { echo "static:", $e->getMessage(), "\n"; }
PHP
PHP_COMPILER_PROFILE=8.4 php bin/vm.php /tmp/self_parent_scope.php'

Done when

  • self/parent/static outside class scope match Zend Error messages on VM/JIT
  • Compliance or test/repro/ guard
  • php-src-strict; no php-compiler-strict shortcut

Trust snapshot (this maintainer run)

  • user_release_ready: yes · inventory OK 7252/7252 · no open worker PRs

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