次のようなフォルダー構造があります
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
と、 someClass not found on .../Scheduled/test.php が表示されます
spl は someClass.php のような拡張クラスで動作しますか、それとも拡張するクラスを含める必要がありますか?
そして、なぜそれが見つからないのsomeClass.php
ですか?
ありがとう