Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReflectionClass cast to "normal" Class

Tags:

php

reflection

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

I have realized the invoke with following code:

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

It work great. But now I want to use my magic method. So I call $class->getData(), but it doesn't work. I get the error, that I called an undefined method.
I tried to use ReflectionMethod and invoke, but it doesn't work again.

Is there no way to cast the ReflectionClass Object to my TableData class?

Thanks for advice!

like image 624
CSchulz Avatar asked Dec 13 '22 20:12

CSchulz


1 Answers

You can't call the method on the instance of ReflectionClass. You have to call the method on the instance of your (reflected) original class.

$class    = new ReflectionClass('TableData');
$instance = $class->newInstanceArgs($parArray);
$instance->getData();
like image 130
Stefan Gehrig Avatar answered Dec 27 '22 03:12

Stefan Gehrig