Skip to content

#244 - Fix MappingTransformer: add a new property to a stdClass destination - #251

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

njoubert-cleverage merged 2 commits into
mainfrom
244

Conversation

@njoubert-cleverage

Copy link
Copy Markdown
Member

Description

Fixes #244.

MappingTransformer could not add a new property to a \stdClass destination (initial_value: new \stdClass(), or keep_input on a \stdClass input): the PropertyAccessor does not consider a missing \stdClass property as writable, and only arrays had a fallback, so it threw Property '...' is not writable.

  • add a \stdClass fallback, next to the array one, for a simple target property name (no ., [ or ], not empty): $result->{$targetProperty} = $transformedValue. A nested path (address.city) or an index notation ([name]) still throws, as for any other object: intermediate objects are not created;
  • document it in docs/reference/transformers/mapping_transformer.md (algorithm, mapping option, note);
  • add tests in MappingTransformerTest: new property with a \stdClass initial_value and with keep_input (both fail on main), and the non-simple paths that keep throwing.

PHPUnit (805 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

None: this case currently throws. Nested paths and other objects behave as before.

🤖 Generated with Claude Code

njoubert-cleverage and others added 2 commits October 9, 2026 10:48
…ty of a `\stdClass` destination (`initial_value` or `keep_input`) threw `Property '...' is not writable`, it is now added when the target is a simple property name (nested paths still throw). Update documentation, add tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@njoubert-cleverage
njoubert-cleverage merged commit 6ce6bc4 into main Oct 9, 2026
17 checks passed
@njoubert-cleverage
njoubert-cleverage deleted the 244 branch October 9, 2026 09:34
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.

MappingTransformer: cannot add a new property to a stdClass destination

1 participant