vendredi 4 janvier 2019

Call to undefined method ReflectionClass::register()

I'm trying to create objects dynamically by its full names (including namespace).

When I write instantiating via new keyword - it works fine

$coreComponents = ['user' => 'app\web\User'];
$component = coreComponents['user'];
$reflectionClass = new $component();

But when I write the code by using Reflection:

$coreComponents = ['user' => 'app\web\User'];
$component = coreComponents['user'];
$reflectionClass = new \ReflectionClass($component);

it shows me the error:

Exception: Call to undefined method ReflectionClass::register()

What does it mean? I didn't find any information about ::register() method, which I do not use. How to fix it?


I use

PHP Version - 7.0.32-0
Ubuntu - 16.04.1





Aucun commentaire:

Enregistrer un commentaire