我有一个看起来像的文件夹结构
base_dir-
Includes.php
Libs-
Database.php
Log.php
Cofing.php
Models-
someClass.php
Scheduled-
test.php
我的Includes.php
有
spl_autoload_register(NULL, FALSE);
spl_autoload_extensions('.php, .class.php, lib.php');
function libLoader($name) {
$file = 'Libs/' . $name . '.php';
if (!file_exists($file)) {
// throw new Exception("Error Loading Library: $file does not exists!", 1);
return FALSE;
}
require_once $file;
}
function modelLoader($name) {
$file = 'Models/' . $name . '.php';
if (!file_exists($file)) {
// throw new Exception("Error Loading Library: $file does not exists!", 1);
return FALSE;
}
require_once $file;
}
spl_autoload_register('libLoader');
spl_autoload_register('modelLoader');
我的someClass.php
有
require_once '../Includes.php';
class someClass extends Database
{
public function __construct() { return 'hello world'; }
}
并且test.php
有
require_once '../Includes.php';
try {
$loads = new someClass();
} catch (Exception $e) {
echo "Exception: " . $e->getMessage();
}
当我运行时,test.php
我在 .../Scheduled/test.php 上找不到 someClass
spl 是否适用于 someClass.php 之类的扩展类,还是我需要包含要扩展的类?
为什么它不会找到someClass.php
?
谢谢