0
votes

Due to performance issues (benchmarked) I'm trying to use another autoloader than the default Zend_Loader_Autoloader.

I tried to different method, using :

$autoloader->removeAutoloader(array('Zend_Loader_Autoloader', 'autoload'))
    ->setDefaultAutoloader(array($loader, 'loadClass'));

Since the Autoloader is heavily linked to most component of Zend Framework I can't "remove it".

I did an Xdebug step by step debug and it looks like the Autoloader works like this :

1) getInstance 2) Check if the called class root is a known namespace and if an autoloader exists for its namespace 3) Put on the stack the non namespaced autoloader 4) Tried autoloader on each autoloader, until a valid in found.

However, in my case my autoloader already do this (I'm using Opl Autoloader with a classMap strategy), I allready register the namspace with their respective path.

So it looks a bit overhead for me because I'd like my autoloader be used at the very begging of the lookup bypassing all Zend checks.

Do you have any ideas on improving that? How could I efficiently use a custom (and performant) autoloader within a Zend Framework project and using Zend_Loader_Autoloader

2
@mario, it's what I actually do, OPL provides a ClassMapLoader and its classMap builder which generates an array like "array('My_Class_Name' => 'My/Class/Name.php'); which is pretty straightforwardTrent

2 Answers

1
votes

The autoloader isn't "heavily linked". You can always use every PSR-0 complaint autoloader you like, but in this case you should not use Zend_Loader_Autoloader to register the autoloader into Zend_Loader_Autoloader to replace Zend_Loader_Autoloader ;)

spl_autoload_register($myAutoload);
1
votes

While not answer by itself this post from the Zend lead, Mathew, might prove helpful in demonstrating how to drop in a replacement autoloader (and a more efficient one at that)

http://mwop.net/blog/262-Backported-ZF2-Autoloaders