Category
language · php-src-strict · closures · compile-time fatal
Problem
php-src rejects function () use ($this) at compile time. This compiler accepts the closure, 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 @ 8d228396dc) |
$f = function () use ($this) { return 1; }; echo "accepted\n"; |
Fatal: Cannot use $this as lexical variable (rc=255) |
accepted (rc=0) |
$this is already bound in instance methods; use ($this) is never legal. Silent accept is a php-src-strict miss, not an error-text nit.
php-src reference
PHP implementation target
lib/ closure compile (php-cfg → opcode) — when a use 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_use_this.php 2>&1 | head -5'
./script/docker-exec.sh -- bash -lc 'php bin/jit.php test/repro/maintainer_gap_use_this.php 2>&1 | head -5'
Done when
Category
language· php-src-strict · closures · compile-time fatalProblem
php-src rejects
function () use ($this)at compile time. This compiler accepts the closure, so illegal programs run and print instead of aborting. VM and JIT both take the accept path.8d228396dc)$f = function () use ($this) { return 1; }; echo "accepted\n";accepted(rc=0)$thisis already bound in instance methods;use ($this)is never legal. Silent accept is a php-src-strict miss, not an error-text nit.php-src reference
Zend/zend_compile.c—zend_compile_closure()/ lexicaluselist; rejects$thisas a captured variablePHP implementation target
lib/closure compile (php-cfg → opcode) — when ausename is$this, emit Zend's compile fatal and abortruntime/*.clogicRepro
Done when
Cannot use $this as lexical variable(rc≠0, noacceptedoutput).phptguard undertest/compliance/cases/language/closure_use_this*.phpt