Skip to content

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

Closed

Description

@njoubert-cleverage

Description

RecursivePropertySetterTransformer: when a \stdClass item does not have the property yet, the item is replaced by a copy in the returned collection, so the object of the input is not modified. The reference documentation states that "object items are modified in place, so the objects of the input are modified too". When the property already exists, the item is modified in place as documented.

Reproduction

transformers:
    recursive_property_setter:
        iterator: items
        set_properties:
            parentId: id
$item = (object) ['label' => 'A'];
$result = $transformer->transform((object) ['id' => 7, 'items' => [$item]], $options);
// $result[0] === $item: false
// $item:      {"label":"A"}
// $result[0]: {"label":"A","parentId":7}

Expected: $result[0] === $item, and $item->parentId === 7.

Reproduced on main (ad31c1f), PHP 8.5, Symfony 8.1, by calling the task / transformer directly. Found while adding the missing tests of #197.

Cause

RecursivePropertySetterTransformer.php#L66: on NoSuchPropertyException, a new object is built with (object) array_merge((array) $item, ...).

Proposed fix

Set the dynamic property on the item itself ($item->{$propertyPath} = $propertyValue) for a simple property path. Add tests.

Requirements

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

Breaking changes

The input \stdClass items are now modified, as documented.

Activity

  1. added a commit that references this issue on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions