How can I disable the Zend_Loader_Autoloader?
What about in your bootstrap.php
protected function _initAutoloader()
{
$this->getApplication()
->getAutoLoader()
->unregisterNamespace("Zend");
// or
$this->getApplication()
->getAutoloader()
->removeAutoloader();
}
I'd suggest using "push autoloader" method of Autoloader, which can recieve other autoloader instance and call it when Namespaces match. Therefore you can use your autoloader along with the zend's one...
I assume you're using Zend_Application
, which automatically sets up the PHP environment, autoloading and bootstrapping. It's very handy. Sadly, setting up Zend_Autoloader
is hard coded into the constructor, and I can't see any way to override it:
public function __construct($environment, $options = null)
{
$this->_environment = (string) $environment;
require_once 'Zend/Loader/Autoloader.php';
$this->_autoloader = Zend_Loader_Autoloader::getInstance();
//snip
}
My first suggestion would be to find a way to make Zend_Autoloader
and your other autoloader work in harmony. I've been using Zend_Autoloader
with the new Doctrine::IsolatedClassLoader
with no problems. The advice about being explicit about autoloader namespaces or using pushAutoloader()
is valid, and should work.
However, if that is not an option, you should probably abandon using Zend_Application
, and handle environment setup and bootstrapping yourself. While an inconvenience, it's shouldn't be too difficult. Most ZF tutorials prior to version 1.8 (which is when Zend_Application
was introduced) provided examples.
Here's a (now outdated) set of slides detailing some of this:
Getting Started With Zend Framework for v1.6
You could manually force the Autoloader to unload, but this may lead to trouble with components depending on it being registered: make sure your other loader covers that.
spl_autoload_unregister(array('Zend_Loader_Autoloader','autoload'));
I stripped this from the constructor of Zend_Loader_Autoloader, and changed it to work outside of the class, and to unregister instead of register the loader.
If you're using the Zend_Application, in your index.php, after creating the instance of ZA, you can get/set the autoloader you want ZF to use:
$app = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/config.ini');
$app->getAutoloader()->setDefaultAutoloader('yourAutoloader');
$app->bootstrap()->run();
HTH
Zend_Loader::registerAutoload('Zend_Loader', false);
Its in the framework documentation http://framework.zend.com/manual/en/zend.loader.html#zend.loader.load.autoload
However, I don't think you should have any problems leaving the zend autoloader enabled as long as you register your autoload callback using spl_autoload_register() so it gets added to the autoload stack.
Using spl_autoload_register, all callbacks will be called to try to satisfy the request. I don't know if the chain will be interrupted once a callback is successful. If it does then its probably controlled by returning true or false in the callbacks.