Skip to content

Language: "$this" / "{$this}" string interp outside object yields empty — Zend Error (Zend/zend_execute.c) #31728

Description

@PurHur

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

  • VM (and JIT/AOT if in scope) throw Error: Using $this when not in object context for "$this" / "{$this}" / heredoc $this outside object context
  • Compliance .phpt or unit guard under test/compliance/cases/ or test/unit/
  • php-src-strict; no php-compiler-strict shortcut

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 / JITbugSomething 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