Category
language · php-src-strict · catch · compile-time fatal
Problem
php-src rejects $this as a catch variable at compile time (zend_compile_catch). This compiler accepts catch (Exception $this) — the illegal program runs and prints instead of aborting. VM and JIT both take the accept path.
rejectThisReassignment() already covers Assign / AssignRef / list-destruct / inc-dec, but catch binding does not go through those ops.
| Repro |
Zend 8.2+ |
VM/JIT (2026-08-18 @ af5eba395e) |
try { throw new Exception('x'); } catch (Exception $this) { echo "accepted\n"; } (inside a method) |
Fatal: Cannot re-assign $this (rc=255) |
accepted (rc=0) |
Silent accept is a php-src-strict miss, not an error-text nit. Sibling of #4865 ($this = …) and #32179 (function foo($this)).
php-src reference
PHP implementation target
lib/Compiler.php compile of Op\Stmt\TryCatch (resolveCatchVariableName around the catch-slot reserve) — when the catch name is this, emit Zend's compile fatal and abort
- AST visitor on
PhpParser\Node\Stmt\Catch_ is also fine if it runs before php-cfg
- 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_catch_this.php 2>&1 | head -5'
./script/docker-exec.sh -- bash -lc 'php bin/jit.php test/repro/maintainer_gap_catch_this.php 2>&1 | head -5'
Done when
Category
language· php-src-strict · catch · compile-time fatalProblem
php-src rejects
$thisas a catch variable at compile time (zend_compile_catch). This compiler acceptscatch (Exception $this)— the illegal program runs and prints instead of aborting. VM and JIT both take the accept path.rejectThisReassignment()already coversAssign/AssignRef/ list-destruct / inc-dec, but catch binding does not go through those ops.af5eba395e)try { throw new Exception('x'); } catch (Exception $this) { echo "accepted\n"; }(inside a method)accepted(rc=0)Silent accept is a php-src-strict miss, not an error-text nit. Sibling of #4865 (
$this = …) and #32179 (function foo($this)).php-src reference
Zend/zend_compile.c—zend_compile_catch(); catch variable named$thisis Cannot re-assign $thisPHP implementation target
lib/Compiler.phpcompileofOp\Stmt\TryCatch(resolveCatchVariableNamearound the catch-slot reserve) — when the catch name isthis, emit Zend's compile fatal and abortPhpParser\Node\Stmt\Catch_is also fine if it runs before php-cfgruntime/*.clogicRepro
Done when
Cannot re-assign $this(rc≠0, noacceptedoutput).phptguard undertest/compliance/cases/language/(e.g.catch_this_compile_fatal.phpt)