ZF-6660: Zend_Gdata_App autoloading bug with class_exists

Issue Type: Bug Created: 2009-05-14T13:46:18.000+0000 Last Updated: 2009-06-23T18:17:36.000+0000 Status: Resolved Fix version(s): - 1.9.0 (31/Jul/09)

Reporter: Jeffrey Sambells (jeffrey) Assignee: Trevor Johns (tjohns) Tags: - Zend_Gdata

Related issues: Attachments:


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.


Posted by Trevor Johns (tjohns) on 2009-05-14T14:06:24.000+0000

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

Posted by Jeffrey Sambells (jeffrey) on 2009-05-14T15:37:45.000+0000

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.

Posted by Trevor Johns (tjohns) on 2009-06-23T18:17:36.000+0000

Fixed for trunk in r16265.

<pre class="literal">
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: <a href="">…</a> 44c647ce-9c0f-0410-b52a-842ac1e357ba

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

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.