Category
Language: · php-src-strict · $this in string interpolation
Problem
Interpolating $this in a double-quoted string, "{$this}", or heredoc outside object context must throw Error: Using $this when not in object context (Zend). VM yields an empty string with no error.
Bare $this as an expression and top-level (fn() => $this)() already match Zend (#10558 / #28814). This gap is string interpolation only.
Probed 2026-08-17 — host Zend PHP 8.2+ vs php bin/vm.php.
| Repro |
Zend 8.2+ |
VM (2026-08-17) |
"$this" at file scope |
Error: Using $this when not in object context |
OK '' |
"{$this}" at file scope |
same Error |
OK '' |
heredoc {$this} at file scope |
same Error |
OK '' |
php-src reference
PHP implementation target
lib/ compile/VM lowering for interpolated $this — raise the same Error as bare $this when no object context; no new runtime/*.c logic
Repro
./script/docker-exec.sh -- bash -lc 'php test/repro/maintainer_gap_this_outside_object_context.php'
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_this_outside_object_context.php'
Done when
Category
Language:· php-src-strict ·$thisin string interpolationProblem
Interpolating
$thisin a double-quoted string,"{$this}", or heredoc outside object context must throwError: Using $this when not in object context(Zend). VM yields an empty string with no error.Bare
$thisas an expression and top-level(fn() => $this)()already match Zend (#10558 / #28814). This gap is string interpolation only.Probed 2026-08-17 — host Zend PHP 8.2+ vs
php bin/vm.php."$this"at file scopeError: Using $this when not in object contextOK ''"{$this}"at file scopeOK ''{$this}at file scopeOK ''php-src reference
Zend/zend_execute.c—$thisfetch / object-context checkZend/zend_vm_def.h—ZEND_FETCH_THIS/ string interpolation compilePHP implementation target
lib/compile/VM lowering for interpolated$this— raise the sameErroras bare$thiswhen no object context; no newruntime/*.clogicRepro
Done when
Error: Using $this when not in object contextfor"$this"/"{$this}"/ heredoc$thisoutside object context.phptor unit guard undertest/compliance/cases/ortest/unit/