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
怎样才能解决这个问题?