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???
You must set a fully qualified name. Because your class is in system\core
namespace:
spl_autoload_register(array('system\core\core', 'autoload'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With