gea*_*ass 5 php namespaces autoloader
这里要问的是我的自动加载器类/函数与spl_autoload_register的任何错误?
感谢帮助.
这是我的代码
<?php
namespace system\core;
// if(!defined('IN_APP')){
// exit('Access Denied');
// }
define('ROOT', $_SERVER['DOCUMENT_ROOT']);
define('DS', DIRECTORY_SEPARATOR);
if(function_exists('spl_autoload_register')){
spl_autoload_register(array('core', 'autoload'));
}else{
function __autoload($class){
return core::autoload($class);
}
}
A:createapp();
class core
{
private static $_app;
public static function createapp(){
if(!is_object(self::$_app)){
self::$_app = 'something';
}
return self::$_app;
}
public static function autoload($class){
$class = trim(strtolower($class));
if(strpos($class, '\\') !== false){
$path = ROOT;
$path .= DS . $class . '.php';
$path = preg_replace('/[\\|\/]/i', DS, $path);
require_once($path);
}
}
}
class A extends core {}
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误
Fatal error: Uncaught exception 'LogicException' with message 'Passed array does not specify an existing static method (class 'core' not found)' in C:\xampp\htdocs\test\system\core.php:14 Stack trace: #0 C:\xampp\htdocs\test\system\core.php(14): spl_autoload_register(Array) #1 {main} thrown in C:\xampp\htdocs\test\system\core.php on line 14
Run Code Online (Sandbox Code Playgroud)
在我读错误消息后,它意味着没有找到类核心?但是这个类写在同一个文件中???
您必须设置一个完全限定名称。因为你的类位于system\core命名空间中:
spl_autoload_register(array('system\core\core', 'autoload'));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3799 次 |
| 最近记录: |