ZF-7191: Zend_Loader_Autoloader::autoload() doesn't invoke anonymous callbacks
Description
When calling $autoloader->(push|unshift)Autoloader($callback) where $callback is a lambda, the callback is added to the stack but is never invoked during the actual autoloading. The autoload() method validates every callback and handles only callbacks of the form $functionName or array($objectOrClassname, $method).
It also might be a good idea to move the callback validation from autoload() to (push|unshift)Autoloader() so that the validation occurs only once and we may throw an exception if the callback passed is invalid.
Comments
Posted by Mon Zafra (monzee) on 2009-11-20T05:23:29.000+0000
My proposed changes, not sure if these are satisfactory. NOTE: The attached AutoloaderTest.diff is for PHP 5.3+ only! * changed the {{autoload}} method, replaced the {{if}} checks for array and string with {{is_callable}} * added {{_validateCallback()}} method which is called by {{setAutoloaders()}}, {{(push|unshift)Autoloader()}} * added {{$validate}} param for {{setAutoloaders()}} which defaults to true. This is because unshift, push and remove all call {{setAutoloaders()}} which would unnecessarily trigger validation for every registered autoloader.
Posted by Ramon Henrique Ornelas (ramon) on 2010-07-16T20:35:24.000+0000
Support the anonymous functions was added in 22481 present in the release 1.10.6.
See ZF-10024.