Fix foreach by-ref on property hooks (#6435) - #6465
Merged
Merged
Conversation
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>
Closed
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
foreach ($arr as &$obj->hookedProp)AssignRefwithASSIGN_REF_FOREACH_PROPERTY_HOOKwhen php-cfg emitsIterator\Value+ optionalPropertyFetchprelude.getBacking/setBacking) without invoking set hooks; in-loop$obj->hookedProp++still uses get/set hooks.$this->fieldtargets 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(was1110)Compliance:
./script/docker-exec.sh -- bash -lc 'vendor/bin/phpunit --filter property_hook_foreach_byref'Regression:
./script/docker-exec.sh -- bash -lc 'vendor/bin/phpunit --filter property_hook_assign_ref'php-src reference
Zend/zend_property_hooks.c— FE_FETCH_R / foreach iteration on hooked propertiesZend/zend_execute.c— foreach by-ref assign pathPHP implementation
lib/Compiler.php,lib/VM.php,lib/SourcePreprocessor/PropertyHooks.php,lib/OpCode.phpASSIGN_REF_FOREACH_PROPERTY_HOOKto VM (lib/JIT.php)Made with Cursor