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
怎樣才能解決這個問題?