Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

here to ask is any error for my autoloader class/function with spl_autoload_register?

appreciate for helping.

here is my code

<?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 {}

and i got this error

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

after i read the error msg, it mean the class core not found? but the class is written in the same file???

like image 462
geass Avatar asked Oct 03 '22 13:10

geass


1 Answers

You must set a fully qualified name. Because your class is in system\core namespace:

spl_autoload_register(array('system\core\core', 'autoload'));
like image 102
meze Avatar answered Oct 13 '22 12:10

meze