Skip to content

Fix property hook asymmetric set visibility (#6898) - #6980

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-6898-property-hook-asymmetric-set
Jun 6, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-6898-property-hook-asymmetric-set

Conversation

@PurHur

@PurHur PurHur commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • Parse PHP 8.4 set (protected|private|public) => / block hook syntax in PropertyHooks and emit phpc-asymmetric-set markers on the lowered property declaration.
  • Enforce asymmetric set visibility before set-hook dispatch in the VM so global-scope writes throw Zend-parity Error instead of silently invoking the set hook.
  • Add compliance PHPT + unit tests.

php-src reference

  • Zend/zend_compile.c — asymmetric set modifier on property hooks
  • Zend/zend_property_hooks.c — hook dispatch with visibility

PHP implementation

  • lib/SourcePreprocessor/PropertyHooks.php — parse + lower asymmetric set hooks
  • lib/VM.php — enforceAsymmetricPropertyWrite() before dispatchPropertySetHookAssign()

Verification

Issue repro (VM):

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "class C{public string \$x{get=>\"g\"; set(protected)=>\$value;}} \$c=new C; echo \$c->x,\"\n\"; try{\$c->x=\"n\";}catch(Error \$e){echo get_class(\$e),\": \",\$e->getMessage(),\"\n\";} echo \$c->x,\"\n\";"'

Output:

g
Error: Cannot modify protected(set) property C::$x from global scope
g

Targeted tests:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter "PropertyHooksTest::testLowersAsymmetric|property_hook_asymmetric"'

Result: OK (3 tests, 9 assertions)

Closes #6898

Made with Cursor

).

Lower `set (protected) =>` hook syntax via phpc-asymmetric-set markers in PropertyHooks,
and enforce asymmetric set visibility before set-hook dispatch in the VM.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 9a242d6 into master Jun 6, 2026
@PurHur
PurHur deleted the agent/issue-6898-property-hook-asymmetric-set branch June 6, 2026 16:55
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: property hooks with asymmetric set visibility set (protected) => — parse fails (zend_property_hooks.c)

1 participant