-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
  • 89,708
  • 20
  • 100
  • 143
AMit SiNgh
  • 171
  • 3
  • 15

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