I have a scenario wherein after upgrading PHPUnit 3.4.11 to version 3.5.3, an existing bootstrap file for phpunit suddenly encountered an error complaining about class was not found. It seems PHP __autoload is not working.
After few experiments, a solution came up as shown below.
This is the previous method of autoloading class.
Now here is the new version that works for PHPUnit 3.5
After few experiments, a solution came up as shown below.
This is the previous method of autoloading class.
if (!function_exists('__autoload')) {
function __autoload($class) {
$file = str_replace('_','/',$class.'.php');
//Suppress errors in case it can't find the file.
@include_once $file;
}
}
Now here is the new version that works for PHPUnit 3.5
function autoload($class) {
$file = str_replace('_','/',$class.'.php');
try{
include_once $file;
} catch (Exception $e) {
}
}
spl_autoload_register('autoload');