Skip to content
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

Default values in target are not handled #8

Closed
nikophil opened this issue Oct 3, 2023 · 0 comments · Fixed by #104
Closed

Default values in target are not handled #8

nikophil opened this issue Oct 3, 2023 · 0 comments · Fixed by #104
Labels
enhancement New feature or request

Comments

@nikophil
Copy link
Collaborator

nikophil commented Oct 3, 2023

This PR made me realize there is another problem, a little bit more complex to mitigate:

readonly class SomeClass
{
    public function __construct(public int|null $foo = 1, public int $bar = 0)
    {
    }
}

$autoMapper->map([], SomeClass::class);

two problems here:

  • foo defaults to null whereas it should default to 1
  • the above code creates an error because key bar is not present, although the property has a default value

I'm not sure how we could fix this... maybe by adding the default value in the WriteMutator?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants