Last modified: 2010-05-15 15:54:51 UTC
Created attachment 5031 [details] Patched Autoloader file that has code to use spl_autoload_register This is a feature request to improve interoperability between MediaWiki and other PHP packages by slightly changing how the autoloader is established. Currently MediaWiki directly defines PHP 5's magic __autoload function. However, if another application has already registered an __autoload this call silently fails and the program crashes the first time it tries to start a class. The solution as of PHP 5.1.2 is function spl_autoload_register(). This function will register Wiki's autoloader. When the Zend engine has an undefined class it will iterate across the autoloaders until one of them returns true (presumably because it found the class). Attached is a corrected Autoload.php file with the changes necessary to use this function. Further if the function is not defined it will define a magic __autoload function for backwards compatibility. Forgive me if I mess this up - I've not worked with bugzilla before.
Forgot to mention - for compliance with other autoloaders the wfAutoload function now returns boolean true or false, previously it returned void.
AutoLoader is already using spl_autoload_register(). Changed AutoLoader::autoload() to return false on failure instead in r36776. Nothing appears to break here, but it could use some additional eyes. I do think that returning false seems like a more logic choice, as it allows for better testing $newClass = new Class() failures rather than an explicit "Class X not found" PHP error.
Returning false also prompts the zend engine to fire the next autoload method on the stack. I would advise against the use of eval("$newClass = new Class():"); because that prevents other any autoloaders that where defined after the wiki autoloader from working. Once a class is defined it can't be undefined - best to fail hard here and give other autoloaders that might be in place a chance to work.
Eval() isn't used _anywhere_ in the code.