namespaces - Question about a simple PHP Autoloader -


i learning aboutt php namespaces , starting create simple autoload function. o did was:

function __autoload($name) {   echo $name . "<br />";   require_once $name . ".php"; } 

so, works if not use aliasing or importing statements eg. use mainnamespace\subnamespace because if did that, assuming have:

\greatapp\models\user.php \greatapp\models\project.php \greatapp\util\util.php \greatapp\util\test\test.php 

if try do:

new greatapp\models\user(); 

it works because $name in autoload become greatapp\models\user greatapp\models\user.php found. when do:

use greatapp\models; new user(); 

it fails because $name user , user.php not found. how should setup autoloading then?

full namespace path passed autoloader no matter how import namespace , reference class. should work.

just __autoload function should belong main (root) namespace


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -