Zend Framework

Zend_Loader_Autoloader::autoload() doesn't invoke anonymous callbacks

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.10.6
  • Component/s: Zend_Loader
  • Labels:
    None

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.

Activity

Hide
Mon Zafra added a comment -

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.
Show
Mon Zafra added a comment - 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.
Hide
Ramon Henrique Ornelas added a comment - - edited

Support the anonymous functions was added in 22481 present in the release 1.10.6.

See ZF-10024.

Show
Ramon Henrique Ornelas added a comment - - edited Support the anonymous functions was added in 22481 present in the release 1.10.6. See ZF-10024.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: