ZF-6660: Zend_Gdata_App autoloading bug with class_exists


r15576 introduced the following bug:

if (!class_exists($name . '' . $class)) { require_once 'Zend/Loader.php'; echo 'test'; @Zend_Loader::loadClass($name . '' . $class); }

which causes things to fail as the class_exists triggers the autoloader to load the class if an autoloader is registered. It should be !class_exists($name . '_' . $class, false) to disable autoloading when checking if the class exists.


Jeffrey, What do you mean by "causes things to fail"? What is the failure you're experiencing?

I've created a new Zend_Gdata object, let's call it My_Gdata_App

I've registered My_Gdata_App however when I use the newAppEntry method, which is processed by a magic __ method in Zend_Gdata, it attempts to load the My_Gdata_App _Entry object from various places. The problem occurs when it checks to see if my extension exists. The class_exists() call invokes the autoloader automatically so I end up with a Zend_Loader::include() error (for My/Gdata/App/Extension/Entry.php) because it can't find the file it was looking for. Not finding it was the expected result since the correct path is in the second loop (My/Gdata/App/Entry.php), but it can't loop since it failed in the first loop.

Basically the if statement itself creates a situation where the code in the brackets will never run since the class_exists will trigger the Zend_Loader to try and load the file to see if it exists. You just need to add the "false" as the second argment to prevent class_exists from invoking autoloading, then your code will load it as necessary.

oh, and ignore the echo 'test'; bit in the original bug, that was me to see if the if statement ever executed.

Fixed for trunk in r16265.

commit 6e759f924cf239eff23a33d4e31d9e89d1eb0a6b
Author: tjohns 
Date:   Wed Jun 24 01:15:52 2009 +0000

    ZF-6660: Disable class_exists() autoloader in Zend_Gdata_App::__call() and
    Zend_Gdata_Gapps::__call() for compatibility with magic factories.
    This corrects a bug that was introduced by r15576.
    Found by: jeffrey (Jeffrey Sambells)
    git-svn-id:… 44c647ce-9c0f-0410-b52a-842ac1e357ba

 library/Zend/Gdata/App.php   |    4 +++-
 library/Zend/Gdata/Gapps.php |    4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)