minor cleanup of singleton handling
authorIngo Renner <ingo.renner@typo3.org>
Mon, 20 Oct 2008 10:40:18 +0000 (10:40 +0000)
committerIngo Renner <ingo.renner@typo3.org>
Mon, 20 Oct 2008 10:40:18 +0000 (10:40 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@4333 709f56b5-9817-0410-a4d7-c38de5d9e867

t3lib/class.t3lib_div.php

index 1093581..7d9ab7f 100755 (executable)
@@ -4584,7 +4584,7 @@ final class t3lib_div {
 
                        // Load class file if not found:
                if (!class_exists($className))  {
-                       if (substr($className,0,6)=='t3lib_')   {
+                       if (substr($className,0,6) == 't3lib_') {
                                t3lib_div::requireOnce(PATH_t3lib.'class.'.strtolower($className).'.php');
                        }
                }
@@ -4593,14 +4593,17 @@ final class t3lib_div {
                $className =  t3lib_div::makeInstanceClassName($className);
 
                if (isset($instances[$className])) {
-                       return $instances[$className];
-               }
-               $instance = new $className;
-               if ($instance instanceof t3lib_Singleton) {
-                       $instances[$className] = $instance;
+                               // it's a singleton, get the existing instance
+                       $instance = $instances[$className];
+               } else {
+                       $instance = new $className;
+
+                       if ($instance instanceof t3lib_Singleton) {
+                                       // it's a singleton, save the instance for later reuse
+                               $instances[$className] = $instance;
+                       }
                }
 
-                       // Return object.
                return $instance;
        }