Details
-
Type:
Improvement
-
Status:
Resolved
-
Priority:
Trivial
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 0.9.0
-
Component/s: Zend_Loader
-
Labels:None
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.");
}
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.