Viacheslav Ravdin
Viacheslav Ravdin

Reputation: 1

ReflectionClass::newInstanceArgs when class constructor has Class ...$class declaration

I'm trying to invoke public ReflectionClass::newInstanceArgs(array $args = []): ?object method on class which has the following constructor:

    public function __construct(Option ...$options) {
        $this->options = $options;
    }

$args has the following structure:

    [options] => Array
        (
            [0] => Hoo\DTOs\Option Object
                (
                    [value] => +370
                    [selected] => 1
                )

            [1] => Hoo\DTOs\Option Object
                (
                    [value] => +371
                    [selected] => 
                )

        )

I'm getting the following error:

[TypeError] 
Hoo\DTOs\Select::__construct(): Argument #1 must be of type Hoo\DTOs\Option, array given (0)

I assume that $args has to be different but I don't really understand how it should look like.

https://www.php.net/manual/en/reflectionclass.newinstanceargs.php doesn't give anything about it so I would appreciate any help.

Upvotes: 0

Views: 28

Answers (0)

Related Questions