I am finding that when Zend tries to auto load a file which doesn't exist, it throws an error which I cannot catch in a try/catch block. This happens when I use class_exists too. I have fixed the problem by hacking zend:
if ($once) {
if (!@include_once ($filename)) {
throw new Exception("Failed to include $filename");
}
// include_once $filename;
}
else {
if (!@include ($filename)) {
throw new Exception("Failed to include $filename");
}
// include $filename;
}
The commented out lines are zend's originals. Now I can catch the exception thrown when a file cannot be included. Can anybody suggest a cleaner way to do this which doesn't involve hacking zend?
I am on Zend version 1.11.10, and the code in question is Zend_Loader line 146.
Thanks.
Don't try and autoload classes that don't exist. If for some reason the class you're trying to autoload may or may not be there, wrap that part of code with a
class_exists()call.I can't think of any reason why you would want
class_exists()to throw an exception on failure since it's sole purpose is to allow you to check for the existence of classes.