-1

I have a class name in variable. I am creating instance and it giving me error. Below is the code example.

use app\controller;

$controller = new controller\$class();

please help.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
AMit SiNgh
  • 325
  • 4
  • 17

1 Answers1

1

expecting u got a classname like 'Order' soemthing like the following should work:

$class = 'Order';
$order = new $class();

U are using the namespace app/controller, so there is no need to write the namespace "controller/" in front of your variable...

that should work:

$controller = new $class(); //without "controller/"
jiGL
  • 175
  • 8