Repository navigation
Conversation
ArrayObjectFilter copied each element through the public copy(), whose first statement resets the object map. That map is what keeps one copy per source object and what guards against cycles, so an object shared inside an ArrayObject was duplicated and a graph whose cycle ran through an ArrayObject recursed until memory ran out. Reach recursiveCopy() through a bound closure, the way the sibling SplDoublyLinkedListFilter already does. DeepCopy::copy() is unchanged. ArrayObjectFilterTest stubbed the copy() call being removed, so it is rewritten against a real DeepCopy like SplDoublyLinkedListFilterTest, keeping its flags and iterator-class assertions.
dualfroz
force-pushed
the
dualfroz/fix-arrayobject-object-map
branch
from
September 5, 2026 22:57
1492387 to
e44a99f
Compare
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.
Problem
ArrayObjectFilter::apply()copies each element through the copier's publicentry point:
DeepCopy::copy()starts a fresh copy, and its first statement isso every element of an
ArrayObjectthrows away the map of already-copiedobjects that the copy in progress is relying on. Two things break.
Shared references are duplicated. The map is what makes DeepCopy give you
one copy per source object; resetting it mid-copy loses that:
A cycle running through an
ArrayObjectnever terminates. The map is alsothe cycle guard, so the ordinary parent/children shape recurses until the
process dies:
The sibling filter already gets this right.
SplDoublyLinkedListFilterreachesthe private
recursiveCopy()through a bound closure and has done so since2017;
ArrayObjectFilterwas added in 2020 (#145) and usedcopy()instead.The same graph through an
SplDoublyLinkedListcopies fine today.Fix
ArrayObjectFilternow uses the same bound-closure approach asSplDoublyLinkedListFilter, so the copy in progress keeps its object map.Nothing about the public
copy()is touched. I want to flag that explicitly,because 13ee92a ("Revert fix, I'm afraid of breaking changes", 2026-08-11)
backed out a change that made
copy()save and restore the map around nestedcalls. That was a change to public behaviour for every caller; this is not --
it only stops one internal type filter from re-entering through the wrong
method, and the observable effect is confined to
ArrayObjectcontents.Tests
DeepCopyTest::test_it_keeps_reference_of_objects_shared_through_an_array_object-- an object shared between two
ArrayObjectkeys and a plain property staysone object after the copy.
DeepCopyTest::test_it_can_copy_graphs_whose_circular_reference_runs_through_an_array_object-- the parent/children graph above completes and the back-reference points at
the copy.
ArrayObjectFilterTest::test_it_keeps_objects_shared_inside_the_array_object_shared-- the same property at the filter level.
ArrayObjectFilterTest::test_it_deep_copies_an_array_objecthad to change: itstubbed
copy()on a Prophecy double, which is exactly the call being removed,and
recursiveCopy()is private so it cannot be stubbed the same way. It is nowwritten the way
SplDoublyLinkedListFilterTestis written -- driven by a realDeepCopyand asserting observable behaviour. Every assertion it made is kept(contents are copied,
ARRAY_AS_PROPSpreserved, iterator class preserved) andthe copy assertion is now
assertNotSame+assertEqualson a real objectrather than a stubbed string. As a side effect the suite no longer emits the
prophesize() is deprecatedwarning.Without the fix,
test_it_keeps_objects_shared_inside_the_array_object_sharedfails and the circular-reference test kills the process with
Allowed memory size of 268435456 bytes exhausted.Gate run on this branch:
vendor/bin/phpunit-- OK (87 tests, 180 assertions), against 84 tests /170 assertions / 1 warning on
master