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

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

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -