Skip to content

#243 - Fix RecursivePropertySetterTransformer: modify stdClass items in place - #249

Merged
njoubert-cleverage merged 2 commits into
mainfrom
243
Oct 9, 2026
Merged

njoubert-cleverage merged 2 commits into
mainfrom
243

Conversation

@njoubert-cleverage

Copy link
Copy Markdown
Member

Description

Fixes #243.

When a \stdClass item did not have the property yet, RecursivePropertySetterTransformer replaced 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 as parent.id, which was and still is added as a literal parent.id property (the PropertyAccessor cannot create the intermediate object); only the identity changes. Non-\stdClass items still throw.

Documentation: docs/reference/transformers/recursive_property_setter_transformer.md. Tests: testMissingPropertyIsAddedInPlaceToStdClassItems (fails on main: the returned item is not the input one) and testMissingNestedPropertyPathIsAddedAsPropertyToStdClassItems.

PHPUnit (803 tests), PHPStan, PHP-CS-Fixer and Rector pass, and the changed files are valid PHP 8.2.

Requirements

  • Documentation updates
    • Reference
    • Cookbooks
    • Changelog
  • Unit tests

Breaking changes

The input \stdClass items 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

njoubert-cleverage and others added 2 commits October 9, 2026 10:47
…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>
@njoubert-cleverage
njoubert-cleverage merged commit ad6a8b5 into main Oct 9, 2026
17 checks passed
@njoubert-cleverage
njoubert-cleverage deleted the 243 branch October 9, 2026 09:31
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.

RecursivePropertySetterTransformer: stdClass items without the property are copied instead of modified in place

1 participant