Reputation: 125
I have always used includes if I have wanted to bring in a class I have never used the autoloader function. When I use the function for some reason I continue to get the error.
" Warning: include_once(classes/user.class.php): failed to open stream: No such file or directory in /home/mjcrawle/phpfiles/preprod/test/index.php on line 6 Warning: include_once(): Failed opening 'classes/user.class.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/mjcrawle/phpfiles/preprod/test/index.php on line 6 Fatal error: Class 'User' not found in /home/mjcrawle/phpfiles/preprod/test/index.php on line 42"
This is what my php include looks like.
require_once('classes/ registereduser.class.php');
This is my autoloader that I am unable to get working. The first letter in my class is a cap that is why I am using string to lower.
function autoloader($class){
include_once('classes/'.strtolower($class).'.class.php');
}
spl_autoload_register(autoloader);
I could use some help on what am I getting wrong on this I cannot figure it out.
Upvotes: 0
Views: 153
Reputation: 165
Some tips : - the directory "classes" is not in your include path. Since php will search there for autoload, you get what is wrong... - add the classes directory to your include path using set_include_path function.
I can't elaborate because i'm using my phone and its keyboard is a pain.
Upvotes: 0