ZF-8364: Zend_Loader_Autoloader_Resource::autoload() should return false if no match is found
Currently (r19141 of the standard trunk), the resource autoloader can produce some unexpected PHP warnings if it accidentally attempts to autoload something that doesn't exist. E.g.:
- Create and configure an instance of the resource autoloader; for example:
require_once 'Zend/Loader/Autoloader.php'; require_once 'Zend/Loader/Autoloader/Resource.php'; $autoloader = new Zend_Loader_Autoloader_Resource(array( 'namespace' => 'My', 'basePath' => '/path/to/my', ));$autoloader->addResourceType('resource', 'resources', 'Resource');
- Attempt to instantiate a class that doesn't exist, but would be in the configured namespace:
$obj = new My_Resource_DoesNotExist();
At this point you'll get two PHP errors. The first is an E_WARNING message indicating that you tried to include a file that doesn't exist; the second is an E_FATAL message indicating that you tried to instantiate a class that doesn't exist.
However, if the behavior of Zend_Loader_Autoloader::autoload() is any indicator, Zend_Loader_Autoloader_Resource::autoload() should instead return false if the expected class cannot be found. This will get rid of the first E_WARNING message and enable a bit more flexible error handling.
For an example of why this would be helpful, please take a look at http://www.doctrine-project.org/jira/browse/DC-137 : Doctrine has a feature that will generate a certain class on the fly if it can't be autoloaded; if the current ZF resource autoloader is registered, this will still work correctly ...but not without generating the E_WARNING message mentioned earlier.