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

Description

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:


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)) {
             return;
         }
 
@@ -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.");
         }

Comments

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.

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.

Additions complete with revision 3655