Skip to content

Language: reject closure use($this) as Zend lexical fatal (#32152) - #32161

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-32152-closure-use-this
Aug 18, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-32152-closure-use-this

Conversation

@PurHur

@PurHur PurHur commented Aug 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • Reject function () use ($this) at compile time with Zend's Cannot use $this as lexical variable (Zend/zend_compile.c zend_compile_closure_binding()).
  • Covers file-scope, method-scope, by-ref, and mixed use lists. Legal use ($a) and auto-bound $this without use are unchanged.
  • PHP compile path only (lib/Compiler.php). No new runtime/*.c. php-src-strict.

Closes #32152

PHP implementation

  • lib/Compiler.phpassertNoThisInClosureUseVars() on closure use lists
  • php-src reference: php/php-src Zend/zend_compile.c zend_compile_closure_binding()

Test plan

  • Issue VM repro
  • Issue JIT repro
  • ./script/phpunit.sh --filter ClosureUseThis
  • Existing ClosureCompileTest|ClosureUseOperandAliasTest

Verification

./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_use_this.php > /tmp/vm32152.out 2>&1; echo EXIT:$?; cat /tmp/vm32152.out'
EXIT:255
PHP Fatal error:  Cannot use $this as lexical variable in /compiler/test/repro/maintainer_gap_use_this.php on line 7

./script/docker-exec.sh -- bash -lc 'php bin/jit.php test/repro/maintainer_gap_use_this.php > /tmp/jit32152.out 2>&1; echo EXIT:$?; cat /tmp/jit32152.out'
EXIT:255
PHP Fatal error:  Cannot use $this as lexical variable in /compiler/test/repro/maintainer_gap_use_this.php on line 7

./script/phpunit.sh --filter ClosureUseThis
OK (10 tests, 20 assertions)

./script/phpunit.sh --filter 'ClosureCompileTest|ClosureUseOperandAliasTest'
OK (12 tests, 19 assertions)

JIT stderr may also include a pre-existing php-cfg Optional parameter $extends deprecation; the fatal substring and rc=255 match Zend. Full VMTest/JITTest suites were not run (not green on master; compare by case name). No differential sweep (compile-time reject, no lowering/CFG shape change for valid programs).

Made with Cursor

php-src zend_compile_closure_binding() forbids $this in a use() list. Compile abort with that message instead of silently accepting the closure.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit adca1cb into master Aug 18, 2026
1 check failed
@PurHur
PurHur deleted the agent/issue-32152-closure-use-this branch August 18, 2026 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Language: closure use($this) compiles — Zend "Cannot use $this as lexical variable" (Zend/zend_compile.c)

1 participant