Skip to content

Upgrading to 3.5.10 has broken function of "autoload" #129

Closed
AlexChesser opened this Issue Jan 20, 2011 · 2 comments

2 participants

@AlexChesser

I just upgraded my PHPUnit from 3.4.15 to 3.5.10 and have found that the existing bootstraps have stopped functioning because __autoload is no longer functioning.

A blog post I found says this is the solution:
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');
(source http://topecoders.blogspot.com/2010/11/phpunit-bootstrap-with-php-autoload.html)

However, I don't think I'll be able to change our legacy applications' autoloader. Is there any way I can change PHPUnit to function the way it used to? Should I roll back to 3.4.x ?

@sebastianbergmann

Did you bother to read the release notes for PHPUnit 3.5? They clearly state

  • PHPUnit now uses an autoloader to load its classes. If the tested code requires an autoloader, use spl_autoload_register() to register it.

The only change required is to add spl_autoload_register('__autoload') in your bootstrap script.

@AlexChesser

Sorry Sebastian. I turned to google for the answer before looking to your documentation. How embarrassing for me. Lesson leaned. Thanks for pointing me to the answer.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.