我玩弄SPL自動加載功能,似乎缺少重要的東西,因爲我目前無法使其工作。這是我目前使用的片段:使用spl_autoload()無法加載類
// ROOT_DIRECTORY translates to /home/someuser/public_html/subdomains/test
define('ROOT_DIRECTORY', realpath(dirname(__FILE__)));
define('INCLUDE_DIRECTORY', ROOT_DIRECTORY . '/includes/classes/');
set_include_path(get_include_path() . PATH_SEPARATOR . INCLUDE_DIRECTORY);
spl_autoload_extensions('.class.php, .interface.php, .abstract.php');
spl_autoload_register();
當我echo get_include_path()
我得到我所期望的路徑:當我運行代碼,我得到這個錯誤信息
// Output echo get_include_path();
.:/usr/lib/php:/usr/local/lib/php:/home/someuser/public_html/subdomains/test/includes/classes/
但是:
Fatal error: spl_autoload() [function.spl-autoload]: Class Request could not be loaded in /home/someuser/public_html/subdomains/test/contact.php on line 5
Request.class.php爲絕對爲位於/ home/someuser/public_html/subdomains/test/includes/classes /目錄中。
我錯過了什麼?
@Yannis Rizos - 這確實是我的問題。讓這個答案,所以我可以投票並給你正確的答案功勞。 – 2010-07-06 15:06:56