Skip to content

Language: reject $this reassignment at compile time (#4865) - #4869

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-4865-reassign-this
Jun 3, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-4865-reassign-this

Conversation

@PurHur

@PurHur PurHur commented Jun 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Reject assignment to $this in user methods at compile time with Zend message Cannot re-assign $this (lib/Compiler.php, zend_compile.c parity).
  • Belt-and-suspenders VM guard on TYPE_ASSIGN, TYPE_ASSIGN_REF, and inc/dec write slots.
  • Repro, compliance phpt, and unit test.

Closes #4865

php-src reference

Verification

Issue repro:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/parity_reassign_this.php; echo zend:$?
php bin/vm.php test/repro-maintainer/parity_reassign_this.php; echo vm:$?
'
PHP Fatal error:  Cannot re-assign $this in /compiler/test/repro-maintainer/parity_reassign_this.php on line 5
zend:255
parseAndCompile failure: target=/compiler/test/repro-maintainer/parity_reassign_this.php: Cannot re-assign $this
PHP Fatal error:  Cannot re-assign $this in /compiler/lib/Compiler.php on line 288
vm:255

Targeted tests:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
vendor/bin/phpunit --filter ReassignThisCompileTest
vendor/bin/phpunit --filter reassign_this
'
OK (2 tests, 3 assertions)
OK (2 tests, 2 assertions)

Made with Cursor

Match Zend zend_compile.c: assigning to $this in user methods is a
compile-time fatal. Add VM guard, repro, compliance phpt, and unit tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit afdb604 into master Jun 3, 2026
@PurHur
PurHur deleted the agent/issue-4865-reassign-this branch June 3, 2026 05:32
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: user methods must reject $this reassignment (zend_compile.c)

1 participant