ZF issue reporting?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

ZF issue reporting?

Post by alex.barylski »

I'm using the Zend_Mail component in my own framework and I encountered anissue with autoloaders (I actually had a similar problem with SwiftMailer and switched to Zend when I grew tired of wrestling with Swift). The problem is, I do not want to use Zend autoloader (incase I have similar issue to SwiftMailer) so I basically manually included dependencies, which for a simple mailer, is not a HUGE deal. Zend however assumes it`s the only library in use and that every file is relative to it`s own include_path base, in thie case a folder named `Zend`

Zend is buried about 3 directories deep in my LIBS directory which is not the base directory, so wheneve I include a Zend class and it has dependencies, most classes will explicitly include them with a include_once or require_once -- UGH!

Why this introduces a problem for me is two fold:

1. Whenever I include a Zend component I must now set the chdir() to the `Zend` directory first and restore when complete or whenever I need to work on files as well -- which thankfully is rare but this is still a PITA.

2. The class Zend_Mail_Transport_Smtp uses a method like class_exists to determine whether any dependencies need be included. However class_exists has an optional parameter which invokes autoload and it`s TRUE by default but looking at the code, it`s obvious this parameter should be set to false as the inclusion of dependencies is explicitly done immediately after.

Lines 190-193

Code: Select all

if (!class_exists($connectionClass)) { 
  require_once 'Zend/Loader.php';
  Zend_Loader::loadClass($connectionClass);
}
Shouldnèt this be:

Code: Select all

if (!class_exists($connectionClass, false)) { 
  require_once 'Zend/Loader.php';
  Zend_Loader::loadClass($connectionClass);
}
Adding this second parameter fixed the issue of errors in my application because now the autoload() is not invoked -- which is conflicting with my own autoloaders() I assume -- because I have not used Zends and my own have no idea how to load Zend classes -- despite following an identical convention.

Anyway, if this is not a credibe fix what would be the better solution. I assume it would be to implement a autoloader for Zend which introduces more problems, due to the fact my autoloaders will fail if they are ever invoked to handle a Zend_ class and visa-versa.

While the naming convention is identical, I have libraries stored in different base directories so I need a custom autoload to basically check the class prefix and set the base path. This works for my internal libraries but not for Zend, because Zend explicitly includes their dependencies using require_once, etc, so whenever the library is used it assumes everything is relative to it -- which is not the case unfortunately.

Suggestions, opinions, etc?

Cheers,
Alex
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: ZF issue reporting?

Post by josh »

No they have it correct, you are supposed to add prefixes to your auto loader, either that or disable it altogether.
I am using swift with zend just fine, had no problems following Chris' instructions that addressed auto loading in particular. I chose swift because I like the way it does templated variable substitution globally for subjects, message bodies, etc.. instead of having to manage a bunch of messy string functions with Zend
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: ZF issue reporting?

Post by Weirdan »

PCSpectra wrote: Zend is buried about 3 directories deep in my LIBS directory which is not the base directory, so wheneve I include a Zend class and it has dependencies, most classes will explicitly include them with a include_once or require_once -- UGH!
The best option here is to remove all require/includes from zend files - simple shell script can do that easily.
PCSpectra wrote: 1. Whenever I include a Zend component I must now set the chdir() to the `Zend` directory first and restore when complete or whenever I need to work on files as well -- which thankfully is rare but this is still a PITA.
You could just add Zend folder to the include_path and call it a day.
PCSpectra wrote: 2. The class Zend_Mail_Transport_Smtp uses a method like class_exists to determine whether any dependencies need be included. However class_exists has an optional parameter which invokes autoload and it`s TRUE by default but looking at the code, it`s obvious this parameter should be set to false as the inclusion of dependencies is explicitly done immediately after.
This is obviously a bug.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: ZF issue reporting?

Post by alex.barylski »

No they have it correct, you are supposed to add prefixes to your auto loader, either that or disable it altogether.
Did you look at the code example? Why would they call autoload while explicitly loading the class anyways? One or the other, clearly in my case it caused a bug.

I am not using Swift with Zend I am using Zend_Mail within my own application. Because I already use autoloaders extensively I disabled Zend's autoloader feature and manually include the dependencies, but...

Because Zend autoloader() is disabled when that snippet of code above gets called, an autoloader() is invoked -- unfortunately it's mine not theirs -- and mine has no knowledge of "Zend" prefixed classes so the include fails.

I have tried adding "Zend_" to my own class loader but for reasons which I cannot remember now it didn't work. Something to do with the fact that Zend classes have explicit file inclusions whcih assume "Zend" is the only library in use (or at least the primary) so when a class gets included automagically from the Zend framework, and that class depends on another class, which it includes with a line such as:

Code: Select all

Zend/Mail/Transport/Abstract.php
The engine pukes on me, because the base directory is not set to "Zend" it's set to "/core" which contains the "libraries" directory which in turn contains the "spectra" and "Zend" libraries.

My own framework does not explicitly include dependent files, so autoloading is a simple matter of including the path to my library files, whereas with Zend, everytime I need a class I would need to chdir() the base directory to "Zend" so it's internal dependency inclusion continues to work.
You could just add Zend folder to the include_path and call it a day.
How do you do that? I tried set_include_path() but that didn't seem to work??? Does this have to be done at the ini level? Maybe I could strip the include_once from the Zend source and use my own autoloader -- which would be best anyways.

I assume you mean by using a series of CLI tools like grep, etc? I don't suppose you know of any existing solutions? :P I hate regex.
This is obviously a bug.
Thank you, for confirming I'm not going nutts or a total idiot. :)

Technically I would be hard pressed to call it a bug, more of an over sight, but it's side effects are causing a bug, which I suppose is the definition of a bug. Ignore me I just woke up from a very long sleep -- I"m starting the hibernation process today. :)

Cheers,
Alex
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: ZF issue reporting?

Post by josh »

PCSpectra wrote: and mine has no knowledge of "Zend" prefixed classes so the include fails.
I would say thats a bug in YOUR auto loader, you could rewrite it to use file_exists. If you want that require statement in the if branch in the Zend code to run, your auto load needs to return false then.

Think about it, the second parameter has to be true for it to work for the other people who DO use auto loaders for the zend files.
Post Reply