PHP namespace and dynamic classname
问题 I've encountered a "weird" thing while experimenting with spl_autoload, namespaces and dynamic class names. I use PHP 5.3.2, call the autoload like this set_include_path(get_include_path().PATH_SEPARATOR."classes".PATH_SEPARATOR."utils"); spl_autoload_extensions(".class.php"); spl_autoload_register(); Now to the core. Suggest following code: new \User\Student; $name="\User\Student"; new $name(); This works fine, file classes/user/student.class.php gets loaded successfully, both constructions