Using spl_autoload() not able to load class

Joh*_*nde 8 php spl spl-autoloader

I'm playing around with the SPL autoload functionality and seem to be missing something important as I am currently unable to get it to work. Here is the snippet I am currently using:

// 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();
Run Code Online (Sandbox Code Playgroud)

When I echo get_include_path() I do get the path I expected:

// Output echo get_include_path();
.:/usr/lib/php:/usr/local/lib/php:/home/someuser/public_html/subdomains/test/includes/classes/
Run Code Online (Sandbox Code Playgroud)

However when I run the code I get this error message:

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 /目录中.

我错过了什么?

yan*_*nis 20

http://www.php.net/manual/en/function.spl-autoload-register.php#96804上有一条评论(匿名)可能适用于您的问题:spl_autoload_register()似乎不是很好玩使用camelcase,在你的情况下可能试图找到request.class.php而不是Request ...

  • 有这样的错误.可笑的是,它仍然是一个问题.我经历了错误系统,并对相关问题进行了投票,这是一个很好的起点:https://bugs.php.net/bug.php?id = 53065. (2认同)