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

  Kiến thức lập trình

I’m trying to invoke ReflectionClass::newInstanceArgs method on class which has the following constructor:

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

$args argument has the following structure:

    [options] => Array
        (
            [0] => HooDTOsOption Object
                (
                    [value] => +370
                    [selected] => 1
                )

            [1] => HooDTOsOption Object
                (
                    [value] => +371
                    [selected] => 
                )

        )

I’m getting the following error:

[TypeError] 
HooDTOsSelect::__construct(): Argument #1 must be of type HooDTOsOption, array given (0)

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

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

New contributor

Viacheslav Ravdin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT