Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using spl_autoload() not able to load class

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();

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/

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 is definitely in the /home/someuser/public_html/subdomains/test/includes/classes/ directory.

What am I missing?

like image 276
John Conde Avatar asked Jul 06 '10 14:07

John Conde


1 Answers

There is a comment (anonymous) on http://www.php.net/manual/en/function.spl-autoload-register.php#96804 that may apply to your problem: spl_autoload_register() doesn't seem to play nice with camelcase, and in your case could be trying to find request.class.php instead of Request...

like image 107
2 revs, 2 users 67% Avatar answered Oct 21 '22 17:10

2 revs, 2 users 67%