Category
language · php-src-strict · static locals · compile-time fatal
Problem
php-src rejects static $this at compile time. This compiler accepts the function-local static declaration in functions and methods, so illegal programs run and print instead of aborting. VM and JIT both take the accept path.
| Repro |
Zend 8.2+ |
VM/JIT (2026-08-18 @ bf1e42be86) |
function foo() { static $this; } echo "accepted\n"; |
Fatal: Cannot use $this as static variable (rc=255) |
accepted (rc=0) |
class C { function m() { static $this; } } |
same fatal |
accepted (rc=0) |
Sibling of #32152 (use ($this) lexical). $this is never a legal function-static name.
php-src reference
PHP implementation target
lib/Compiler.php function-local static $var compile (#2286 / #3533 static-local path) — when the name is $this, emit Zend's compile fatal and abort
- Same path for JIT/AOT; no new
runtime/*.c logic
Repro
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_static_this.php 2>&1 | head -5'
./script/docker-exec.sh -- bash -lc 'php bin/jit.php test/repro/maintainer_gap_static_this.php 2>&1 | head -5'
Done when
Category
language· php-src-strict · static locals · compile-time fatalProblem
php-src rejects
static $thisat compile time. This compiler accepts the function-local static declaration in functions and methods, so illegal programs run and print instead of aborting. VM and JIT both take the accept path.bf1e42be86)function foo() { static $this; } echo "accepted\n";accepted(rc=0)class C { function m() { static $this; } }accepted(rc=0)Sibling of #32152 (
use ($this)lexical).$thisis never a legal function-static name.php-src reference
Zend/zend_compile.c—zend_compile_static_var(); rejects$this(Cannot use $this as static variable)PHP implementation target
lib/Compiler.phpfunction-localstatic $varcompile (#2286/#3533static-local path) — when the name is$this, emit Zend's compile fatal and abortruntime/*.clogicRepro
Done when
Cannot use $this as static variable(rc≠0, noacceptedoutput) for function and method forms.phptguard undertest/compliance/cases/language/(e.g.static_this_compile_fatal.phpt)