Skip to content

Fix foreach by-ref on property hooks (#6435) - #6465

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-6435-property-hook-foreach-byref
Jun 5, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-6435-property-hook-foreach-byref

Conversation

@PurHur

@PurHur PurHur commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Tag foreach ($arr as &$obj->hookedProp) AssignRef with ASSIGN_REF_FOREACH_PROPERTY_HOOK when php-cfg emits Iterator\Value + optional PropertyFetch prelude.
  • VM writes iteration scalars to arrow-hook backing storage (registry getBacking/setBacking) without invoking set hooks; in-loop $obj->hookedProp++ still uses get/set hooks.
  • Preprocessor records $this->field targets from arrow get/set hooks for backing resolution.

Closes #6435

Verification

Issue repro:

./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro-maintainer/parity_property_hook_foreach_byref.php'

Output: 40 (was 1110)

Compliance:

./script/docker-exec.sh -- bash -lc 'vendor/bin/phpunit --filter property_hook_foreach_byref'
OK (1 test, 1 assertion)

Regression:

./script/docker-exec.sh -- bash -lc 'vendor/bin/phpunit --filter property_hook_assign_ref'
OK (1 test, 1 assertion)

php-src reference

  • Zend/zend_property_hooks.c — FE_FETCH_R / foreach iteration on hooked properties
  • Zend/zend_execute.c — foreach by-ref assign path

PHP implementation

  • lib/Compiler.php, lib/VM.php, lib/SourcePreprocessor/PropertyHooks.php, lib/OpCode.php
  • JIT defers ASSIGN_REF_FOREACH_PROPERTY_HOOK to VM (lib/JIT.php)

Made with Cursor

Zend FE_FETCH_R assigns iteration scalars to the storage read by get hooks without invoking set hooks; in-loop inc/dec still routes through get/set. Record arrow-hook backing fields in the preprocessor registry and tag foreach AssignRef opcodes so the VM can target the correct cell instead of aliasing the array element.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 06463a1 into master Jun 5, 2026
@PurHur
PurHur deleted the agent/issue-6435-property-hook-foreach-byref branch June 5, 2026 23: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: foreach by-reference on property hooks must invoke set hook (zend_property_hooks.c)

1 participant