逻辑异常错误: 传递的数组未指定现有的静态方法


LogicException error: Passed array does not specify an existing static method

在这里问我的自动加载器类/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 {}

我得到了这个错误

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

我读完错误消息后,表示找不到类核心? 但是类是写在同一个文件中的???

必须设置完全限定的名称。因为您的类位于命名空间system'core

spl_autoload_register(array('system'core'core', 'autoload'));