-
-
Notifications
You must be signed in to change notification settings - Fork 185
Conversation
Default values work with MapFrom
@gerpo - I think this is the right direction, especially by using the reflection property's
Make sense? |
Removing unnecessary check and making setting more explicit.
Removing unnecessary check and making setting more explicit.
@aidan-casey |
Dear contributor, because this pull request seems to be inactive for quite some time now, I've automatically closed it. If you feel this pull request deserves some attention from my human colleagues feel free to reopen it. |
This should be re-opened 👍 |
@gerpo - Can you modify this PR to use the default parameter for |
Done :) |
Thank you, @gerpo. Apologies for the delay! |
This is awesome. I literally just ran into this today. Talk about good timing. Thanks @aidan-casey & @gerpo you're lifesavers. ❤️ |
I think this is introducing a new bug, or if it's intended, that's a breaking change. Before this PR, properties that had a default value, would be assigned the default value if the argument was Now with The following test was green until this PR. $data = [
'title' => 'Hello world',
'description' => null,
];
$dto = new class ($data) extends DataTransferObject {
public string $title;
public string $description = 'Test Text';
};
$this->assertEquals('Hello world', $dto->title);
$this->assertEquals('Test Text', $dto->description); Now this test throws an error:
|
@sebdesign - Please see #282. The behavior you are describing was never intended, documented, or a supported feature. It is not a breaking change worthy of a major release because it was a bug that was fixed in this PR. |
For me this introduced a new bug in my application. I have a base class which extends class BaseDTO extends DataTransferObject
{
public MyObject $myObject;
public function __construct(...$args)
{
// set default
$this->myObject = new MyObject();
// call parent
parent::__construct(...$args);
}
} Now this fails because when the parent constructor runs, it tries to set |
Default values work with MapFrom.
The issue with assign null to type, was that the default value was ignored if the mapping was not present.
Now it will fall back to the default if the mapped property is not present.