Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/php-extension/src/ConstructableFromArrayTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ public static function fromArray(array $data)
);
}

$argument = $data[$parameterName] ?? $reflectionParameter->getDefaultValue();
if ($reflectionParameter->isVariadic() && \is_array($argument)) {
$class = $reflectionParameter->getClass();
if ($class && ($className = $class->getName()) && class_exists($className)) {
$argumentList[] = new $className($argument);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like, at this point, $argument does not exist, right?

You removed line 48, which gets the argument.
Also, what happens if the argument is already an instance of the specified class? It looks like your code will try to instantiate the class with and instance of that same class as the argument.
And what happens if that class needs to be instantiated with several arguments?
It feels like we would be going in the direction of creating a DIC...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I share your thoughts. Apparently, without DIС, unfortunately can not do

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, these are models. They cannot have initiation requiring a DIC

} elseif ($reflectionParameter->isVariadic() && \is_array($argument)) {
$argumentList = \array_merge($argumentList, $argument);
} else {
$argumentList[] = $argument;
Expand Down