I'm running PHP 5.3.4 on Windows 7 and had some difficulty autoloading classes using class_exists(). In my case, when I checked for the class and it didn't exist, class_exists automatically threw a system Exception. I was also throwing my own exception resulting in an uncaught exception.
<?php
$include_path = array( '/include/this/dir', '/include/this/one/too' );
set_include_path( $include_path );
spl_autoload_register();
try {
if( ! file_exists( 'myfile.php' ) ) {
throw new MyException('Doh!');
}
include( 'myfile.php' );
}
catch( MyException $e ) {
echo $e->getMessage();
}
$classname = 'NonExistentClass';
try {
if( ! class_exists( $classname ) ) {
throw new MyException('Double Doh!');
}
$var = new $classname();
}
catch( MyException $e ) {
echo $e->getMessage();
}
?>
By registering an additional autoload handler function that did nothing, I was able to stop throwing the extra Exception and only throw my own.
<?php
$include_path = array( '/include/this/dir', '/include/this/one/too' );
set_include_path( $include_path );
spl_autoload_register();
spl_autoload_register( 'myAutoLoad' ); function myAutoLoad() {}
?>
Found this buried in some search results. I don't remember the page URL but if it would have been here it might have saved me some time!