Page 1 of 1

Zend_Loader, horrible. Doesn't care about other autoloaders

Posted: Wed Feb 18, 2009 7:12 pm
by Chris Corbyn
It appears the in ZF, Zend_Loader just goes ahead and turns any class name into a path then tries to include() the file without even checking if the file exists.

This means that you cannot use spl_autoload_register() to add your own autoload logic. Am I missing something or is this as stupid as it sounds? The whole point of spl_autoload_register() was to allow multiple implementations unlike the initial __autoload() incarnation.


From my email exchange:
I've just looked at the code for Zend_Loader. That's horrible, it just tries to include anything that is passed to it without any regard for other autoloaders.

The only real workaround would be to include Swift's swift_required.php file *before* loading Zend_Loader. This seems like a terrible oversight of Zend... what's the point of spl_autoload_register() if they're going to break the fact you can use multiple autoloaders?

Sigh.


On 19/02/2009, at 2:01 AM, Brandon! wrote:


That would appear to be the case. I verified that this still exists
even in the ZF trunk.

Is there a way we can work around this limitation?

Brandon

On Feb 17, 4:55 pm, Chris Corbyn <ch...@w3style.co.uk> wrote:
That's not too good, it looks like zend's autoloader tries to include
classes before checking they exist.

I'll check this further shortly, but it's either a bug in zf or a
misconfiguration in the bootstrap. You didn't by any chance add swift
mailer to the include path did you?

Sent from my iPhone

On 18/02/2009, at 5:42 AM, "Brandon!" <bran...@mens...store.com>
wrote:



I am trying to use this package in an application where another
autoload function are already in use. When I simply include the
swift_required.php file, I receive a few PHP warning messages:
Warning [2] Zend_Loader::include_once(Swift/DependencyContainer.php)
[<a href='zend-loader.include-once'>zend-loader.include-once</a>]:
failed to open stream: No such file or directory
Error on line 83 in file /home/httpd/vhosts/.../httpdocs/lib/Zend/
Loader.php
Warning [2] Zend_Loader::include_once() [<a
href='function.include'>function.include</a>]: Failed opening 'Swift/
DependencyContainer.php' for inclusion (include_path='.:/usr/local/
lib/
php:/home/httpd/vhosts/.../httpdocs:/home/httpd/vhosts/.../httpdocs/
app:/home/httpd/vhosts/.../httpdocs/lib')
Error on line 83 in file /home/httpd/vhosts/.../httpdocs/lib/Zend/
Loader.php
Warning [2] Zend_Loader::include_once(Swift/Preferences.php) [<a
href='zend-loader.include-once'>zend-loader.include-once</a>]: failed
to open stream: No such file or directory
Error on line 83 in file /home/httpd/vhosts/.../httpdocs/lib/Zend/
Loader.php
Warning [2] Zend_Loader::include_once() [<a
href='function.include'>function.include</a>]: Failed opening 'Swift/
Preferences.php' for inclusion (include_path='.:/usr/local/lib/php:/
home/httpd/vhosts/.../httpdocs:/home/httpd/vhosts/.../httpdocs/app:/
home/httpd/vhosts/.../httpdocs/lib')
Error on line 83 in file /home/httpd/vhosts/.../httpdocs/lib/Zend/
Loader.php

Registered autoloaders are:
Array
(
[0] => Array
(
[0] => MUS_Loader
[1] => autoload
)
[1] => swift_autoload
)

Do I have to do something special to get this autoloader to play well
with others? Do I need to tweak my autoloader to work with swift?

Here's my MUS_Loader just in case its relevant:
class MUS_Loader extends Zend_Loader {
public static function autoload($class) {
$response = parent::autoload($class); //trap the response
/* snipped */
return $response;
}
}

Using Swiftmailer 4.0.0-b5 and Zend 1.5.3
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Swift Mailer" group.
To post to this group, send email to swiftmailer@googlegroups.com
To unsubscribe from this group, send email to swiftmailer+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/swiftmailer?hl=en
-~----------~----~----~----~------~----~------~--~---