Possible Duplicate:
PHP namespace with Dynamic class name
How to declare class from string?
$name = 'the_class';
require_once $name.'.php';
$class = new \resource\$name();
Parse error: syntax error, unexpected '$name' (T_VARIABLE), expecting identifier (T_STRING)
You will need to dynamically construct the namespace path:
$classPath = '\\resource\\' . $name;
$class = new $classPath;
Note: I like to be explicit with literal backslashes.
The namespace needs to be part of the string:
$name = 'the_class';
require_once $name . '.php';
$className = '\resource\\' . $name;
$class = new $className();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With