ZF-937: Add interface awareness to Zend::loadClass()

Issue Type: Improvement Created: 2007-02-21T15:45:35.000+0000 Last Updated: 2007-07-05T14:43:50.000+0000 Status: Resolved Fix version(s): - 0.9.0 (17/Mar/07)

Reporter: Matthew Weier O'Phinney (matthew) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Loader

Related issues: Attachments:


Zend::loadClass() uses class_exists() as a test to see if the class has been previously loaded and/or determine if the class was successfully loaded following a loadFile() operation. This poses a problem as an interface will cause class_exists() to report false, and thus using Zend::loadClass() in autoload will often result in false negatives.

A simple solution is presented in the following diff:

<pre class="highlight">
Index: Zend.php
--- Zend.php    (revision 3503)
+++ Zend.php    (working copy)
@@ -68,7 +68,7 @@
     static public function loadClass($class, $dirs = null)
-        if (class_exists($class, false)) {
+        if (class_exists($class, false) || interface_exists($class, false)) {
@@ -102,7 +102,7 @@
         self::loadFile($file, $dirs, true);
-        if (!class_exists($class, false)) {
+        if (!class_exists($class, false) && !interface_exists($class, false)) {
             throw new Zend_Exception("File \"$file\" was loaded "
                                . "but class \"$class\" was not found within.");


Posted by Gavin (gavin) on 2007-02-21T16:54:10.000+0000

This change is nicely unobtrusive :), and won't lead to the confusion that existed when we had both loadClass() and loadInterface(). However, the burden is on us to show clear use cases justifying supporting the loading of interfaces this way.

Posted by Shaun Rowe (shakie) on 2007-02-22T14:45:52.000+0000

I would also like to see this implemented. This presented itself to me as a problem just last week and I was going to suggest a very similar fix, I also agree with Gavin's comment.

Posted by Matthew Weier O'Phinney (matthew) on 2007-02-26T20:01:16.000+0000

Additions complete with revision 3655

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.