Category
language · compile-time
Problem
Assigning to $this inside a user method is a compile-time fatal in Zend (Cannot re-assign $this). This compiler accepts $this = new C(); and continues execution.
php-src reference
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:$?
'
| Engine |
Output |
exit |
| Zend |
Fatal error: Cannot re-assign $this |
255 |
| VM |
prints reassigned |
0 |
Repro script: test/repro-maintainer/parity_reassign_this.php
Scope (this repo)
| Area |
Files |
| Compiler |
lib/Compiler.php / CFG builder — reject $this as assignment target in user functions |
| VM |
belt-and-suspenders runtime guard if compile path missed |
| Tests |
test/compliance/cases/language/reassign_this.phpt |
Done when
Links
Category
language·compile-timeProblem
Assigning to
$thisinside a user method is a compile-time fatal in Zend (Cannot re-assign $this). This compiler accepts$this = new C();and continues execution.php-src reference
Zend/zend_compile.c— assignment to$thisrejected at compile timeZend/zend_language_parser.yRepro
Fatal error: Cannot re-assign $thisreassignedRepro script:
test/repro-maintainer/parity_reassign_this.phpScope (this repo)
lib/Compiler.php/ CFG builder — reject$thisas assignment target in user functionstest/compliance/cases/language/reassign_this.phptDone when
$thisreads/writes to properties still work./script/ci-fast.sh --filter reassign_thisgreenLinks