2011-06-13 58 views
1

我想自动加载我的PHP 5.3命名空间类例如。如何自动加载PHP 5.3类?

/JM 
    Auth.php 
    User.php 
    Db/Entity.php 
    /... 

我做

namespace KM; 

class Autoloader { 
    public static function registerAutolaod() { 
     ini_set('include_path', dirname(__FILE__) . PATH_SEPARATOR . ini_get('include_path')); 
     spl_autoload_register(function ($classname) { 
      $file = preg_replace('/\\\/', DIRECTORY_SEPARATOR, $classname) . '.php'; 
      echo $file . '<br />'; 
      include ($file); 

     }); 
    } 
} 

问题是有时我得到的类名作为User有时KM\User怎样才能解决这个问题?

回答