Hi Matthew,

>> My point, or preference is, is that we should try and encourage only
>> registering one autoloader handler for the application.
>
> Why, exactly? What problem does this solve?
>
> This is in fact how the StandardAutoloader (PSR-0 implementation) in ZF2
> works -- you register explicit namespace/path pairs; if the requested
> class does not match the given namespace, it moves on to the next
> handler.

In my opinion, therein lays the problem. Each handler's register
method is registering with spl_autoload_register, which the developer
cannot halt if a class for a particular namespace is not found, since
the handler's autoload method typically returns false, causing the
spl_autoloader to move onto the next registered handler (there is no
way of preventing _spl_ from continuing?).

For example, say the StandardAutoloader is registered and has had
namespace 'Ant' registered with it. And another handler is also
registered with the spl_autoload_register (similar to what's in the
quickstart). Then if class_exists is called for 'Ant\test', the
standard autoloader will return false (since it doesn't exist),
causing the spl_autoloader to move onto the next registered handler
when it shouldn't, especially when chances are none of the other
handlers know anything about that namespace.

So instead, I'm thinking, there should be only one (stack like)
handler registered via spl_autoload_register, and any other handlers
would register with that single stack like handler instead of directly
registering with the spl_autoloader. This would give the handler a way
to indicate that the autoloading mechanism should halt its process and
not waste any more cycles or file/io lookups.

For example, with the ZF1 code I wanted to try an optimize the
autoloading mechanism after introducing the Class Map back port you
provided. Try making that handler the only autoloader for ZF1, its not
clean. And with a class map to hand there is no need for the View
Helper to file hunt, try changing file_exists to class_exists and
notice the unnecessary subsequent autoloader calls if more than one
handler is registered with spl.


Regards,

Greg

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to