The main problem is that use cannot have a variable as part of it as it's used when parsing the file and the variable is only available at runtime.
This is an example of how you can do what you seem to be after...
<?php namespace Controller; ini_set('display_errors', 'On'); error_reporting(E_ALL); class Index { public function show() { echo "Showing..."; } } $classandmethod = "Controller\Index@show"; list($className,$method) = explode("@", $classandmethod); $a= new $className(); $a->$method();
This displays...
Showing...
You could of course say that all of these classes must be in the Controller namespace and so the code will change to
$classandmethod = "Index@show"; list($className,$method) = explode("@", $classandmethod); $className = "Controller\\".$className; $a= new $className(); $a->$method();