Search code examples
phpdoctrineclassloaderautoload

Doctrine classloader overwrites my __autoload function


I may generally misunderstand something about setting up a custom classloader.

What happens is that once i initialize it:

use Doctrine\Common\ClassLoader;

require_once(DOCTRINE_PATH . '/Common/ClassLoader.php');
classLoader=new ClassLoader('Doctrine', DOCTRINE_PATH);
classLoader->register();

My previously defined function

function __autoload(){}

No longer works.

What am i missing here?


Solution

  • After diving a bit deeper into the autoload documentation, i found that in order to have multiple autoloaders at the same time, the use of

    function __autoload(){}
    

    is not a valid route to take. Instead, one has to define a custom autoload function, such as

    function MyAutoLoader()
    

    and then use

    spl_autoload_register('MyAutoLoader');
    

    to register it onto the autoload stack.

    Finally, using this method, my autoloader is no longer overwritten by implementing the Doctrine classloader.