ReflectionClass added to class "normal"

I have a TableData class with two magic methods. One of them is the constructor, and the other is the __call method.

I understood the call with the following code:

$class = new ReflectionClass('TableData');
$class->newInstanceArgs($parArray);

It works great. But now I want to use my magic method. Therefore I call $class->getData(), but it does not work. I get an error that I called the undefined method.
I tried to use ReflectionMethod and call, but it does not work again.

Is it impossible to apply the ReflectionClass object to the TableData class?

Thanks for the advice!

+3
source share
3 answers

ReflectionClass. () .

$class    = new ReflectionClass('TableData');
$instance = $class->newInstanceArgs($parArray);
$instance->getData();
+9

baout ReflectionClass:

class MyClass {
  public function __call($method, $args) {
    var_dump($method);
  }
}

$reflectionClass = new ReflectionClass('MyClass');

, :

$class = $reflectionClass->newInstanceArgs();

$class:

$class->getData();

:

string 'getData' (length=7)


.. , newInstanceArgs, ReflectionClass.

+2

, Reflection. , , ?

Reflection - : :

$instace = new TableData($parArray);

:

$class    = new ReflectionClass('TableData');
$instance = $class->newInstanceArgs($parArray);

, , , , func_get_args:

class TableData {
    public function __constructor() {
        if (func_num_args() != 1 || !is_array($params = func_get_arg(0))) {
            $params = func_get_args();
        }

        // now the args are in $params either way
    }
}
0

Source: https://habr.com/ru/post/1754381/


All Articles