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 succeed. However, a bit different usage:
$name="\User\Student";
new $name();
new \User\Student;
fails on "..Class \User\Student could not be loaded...". I suggest it should be related to the static/dynamic namespace resolution somehow. However, I don't think there should be any difference between these two except for the time they are processed at (compilation vs. runtime).
Thanks for any explanation.