-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hey! Thanks for your PR. You are targeting branch "7.4" but it seems your PR description refers to branch "7.3". Cheers! Carsonbot |
|
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)]
private string $nameUpper;
public function __construct(string $name)
{
$this->nameUpper = strtoupper($name);
}
}
$mapper = new ObjectMapper();
$source = new stdClass();
$source->name = 'John';
$target = $mapper->map($source, Target::class); |
|
@frozenbrain nice catch, the PR now covers that case as well. See commit e6009b3 for details on the fix. The issue related to the 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? |
soyuka
left a comment
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
d82e183 to
94fb2a6
Compare
|
Thank you @rvanlaak. |
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.