3

I've an object which returns a string and I would like instanciate another object with the string returned, why in PHP I can't instanciate this way ?

For Example:

// getController() returns a string name controller
$c = new $this->router->getController() ;


// I have to do this way:
$controller = $this->router->getController() ;
$c = new $controller() ;

Thank you for your help.

Malek KARKI
  • 141
  • 2
  • 7

1 Answers1

0

It's a syntax thing. I think I remember seeing an RFC to allow more dynamic class instantiation, but assigning to a variable first gets the job done, no?

landons
  • 9,502
  • 3
  • 33
  • 46