Fix array copy-on-write: keep source after mutating copy (#5340) - #5371
Merged
Merged
Conversation
After list-destructuring by-ref work (#4438), TYPE_ASSIGN cleared arg3 even when it was a live named variable like $a in `$c = $a`, breaking copy-on-write so mutating the copy left the source NULL. Only release compiler temporaries; keep named scope slots intact. Co-authored-by: Cursor <cursoragent@cursor.com>
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
$c = $afollowed by$c[0] = 99left$aasNULLinstead of[1].TYPE_ASSIGNinlib/VM.phpnulled arg3 after every assignment (added for list-destructuring by-ref in Fix list destructuring by-ref semantics (#4433) #4438), including named variables like$a.Block::isNamedVariableSlot()and only release compiler temporaries after assign; named locals are preserved.php-src reference
Zend/zend_array.c—zend_array_separate()COW split on writeZend/zend_variables.c— zval separation; source zval must survive shared HashTable until refcount drops naturallyVerification
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/issue5340_array_cow.php'Output (matches Zend semantics):
./script/docker-exec.sh -- bash -lc 'php vendor/bin/phpunit test/unit/ArrayCowAssignTest.php test/unit/ListDestructKeyedByRefNestedTest.php test/compliance/VMTest.php --filter array_cow'All green (2 ArrayCowAssign unit tests, list destructuring regression, 2 compliance phpts).
Closes #5340
Made with Cursor