Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[ObjectMapper] Preserve non-promoted constructor parameters#61785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
carsonbot commentedSep 18, 2025
Hey! Thanks for your PR. You are targeting branch "7.4" but it seems your PR description refers to branch "7.3". Cheers! Carsonbot |
frozenbrain commentedSep 18, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
If non-promoted constructor parameters are now valid mapping targets, should we also support putting the Also, one thing I noticed is that with this change a property with the same name as the constructor parameter has to exist, is that intentional? For example, the following code throws an exception, because class Target { #[Map(if:false)]privatestring$nameUpper;publicfunction__construct(string$name) {$this->nameUpper =strtoupper($name); }}$mapper =newObjectMapper();$source =newstdClass();$source->name ='John';$target =$mapper->map($source, Target::class); |
@frozenbrain nice catch, the PR now covers that case as well. See commite6009b3 for details on the fix. The issue related tothe following comment: // this may be filled later on see storeValueWhen the property name differs from the constructor argument name, the constructor argument's value did actually not get filled in at a later time. It are the properties that get iterated over later on, which isn't aware of the constructor argument name anymore (as property field had a different name). |
Failing check is unrelated. @soyuka can you help with reviewing this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
indeed good catch
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
d82e183 to94fb2a6CompareThank you@rvanlaak. |
f324858 intosymfony:7.3Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
The object mapper does already call the constructor, but its argument values were not determined / collected correctly as non-promoted parameters were skipped. Can not find or think of a valid reason for that. This PR fixes that the non-promoted constructor parameter values will get resolved and thereafter get mapped.