Repository navigation
#243 - Fix RecursivePropertySetterTransformer: modify stdClass items in place - #249
Merged
Merged
Conversation
…Class` item without the property was replaced by a copy in the output, so the input object was not modified; the property is now added to the item itself. Update documentation, add tests. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.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.
Description
Fixes #243.
When a
\stdClassitem did not have the property yet,RecursivePropertySetterTransformerreplaced it by a copy ((object) array_merge((array) $item, [...])) in the returned collection, so the object of the input was not modified, contrary to the documentation ("object items are modified in place"). When the property already existed, the item was modified in place.The property is now added to the item itself (
$item->{$propertyPath} = $propertyValue). The output content is unchanged, including for a nested path such asparent.id, which was and still is added as a literalparent.idproperty (the PropertyAccessor cannot create the intermediate object); only the identity changes. Non-\stdClassitems still throw.Documentation:
docs/reference/transformers/recursive_property_setter_transformer.md. Tests:testMissingPropertyIsAddedInPlaceToStdClassItems(fails onmain: the returned item is not the input one) andtestMissingNestedPropertyPathIsAddedAsPropertyToStdClassItems.PHPUnit (803 tests), PHPStan, PHP-CS-Fixer and Rector pass, and the changed files are valid PHP 8.2.
Requirements
Breaking changes
The input
\stdClassitems lacking the property are now modified, as documented: code relying on the input staying untouched sees the mutation. The output content is the same.🤖 Generated with Claude Code