0
我剛開始在我的應用程序中使用自動加載器延遲加載,並且與名稱空間發生衝突。自動加載器試圖加載諸如new DateTime()
之類的東西並且失敗。有沒有什麼竅門讓我的自動加載器只有我自己的命名空間類?限制我的spl_autoloader只加載我名字空間中的類?
這是我目前的代碼。我懷疑這是一個爛攤子,但我沒有看到只是如何糾正它:
<?php namespace RSCRM;
class Autoloader {
static public function loader($className) {
$filename = dirname(__FILE__) .'/'. str_replace("\\", '/', $className) . ".php";
if (file_exists($filename)) {
include_once($filename);
if (class_exists($className)) {
return TRUE;
}
}
return FALSE;
}
}
spl_autoload_register('\RSCRM\Autoloader::loader');
快樂RTM,如果有人可以指向一個堅實的例子。
謝謝@Burnsy。 –