我正在更新我的代碼並試圖使用spl_autoload_register,但它很簡單,不工作! 我在Centos/Ubuntu/Win7上使用PHP 5.3.8 - Apache 2.22並嘗試回顯某些內容,但我沒有收到任何內容......一直試圖使其在最後3個小時內沒有任何結果...此操作正在讓我瘋狂!PHP spl_autoload_register什麼都不做
class ApplicationInit {
// Constructor
public function __construct() {
spl_autoload_register(array($this, 'classesAutoloader'));
echo 'construct working...!';
}
// Autoloading methods
public function classesAutoloader($class) {
include 'library/' . $class . '.php';
echo 'autoload working...!';
}
}
從__construct作品,但「classesAutoloader」不工作的時候第一個回波,這個類是在一個文件夾中的PHP文件中定義的,我從喜歡的index.php以下稱之爲:
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', getcwd() . DS);
define('APP', ROOT . 'application' . DS);
// Initializing application
require(APP.'appInit.php');
$classAuto = new ApplicationInit();
任何幫助是真正感激,在此先感謝!
您是否看到''構造工作......!'? –
它沒有做任何事情,因爲你不想引用任何未加載的類。在'$ classAuto'之後,添加一些類似'new SomeClassThatDoesntExist()'的東西,你會看到'classsesAutoloader()'試圖加載一些不會退出的類。 – nickb
是的,我這樣做,謝謝你的回答,但是......做你剛剛所說的話,對我來說,就像做文件包括沒有spl_autoload_register一樣...... – CABP