]> granicus.if.org Git - php/commitdiff
fix the singleton and factory methods for
authorChuck Hagenbuch <chagenbu@php.net>
Tue, 6 Nov 2001 21:46:41 +0000 (21:46 +0000)
committerChuck Hagenbuch <chagenbu@php.net>
Tue, 6 Nov 2001 21:46:41 +0000 (21:46 +0000)
a). php 4.0.6 (where include_once might return false)
b). to use references and not copy so many objects

pear/Log.php

index f4c029c002bd1661e1e13af262a1fb295fc82283..1df0928f535bc03942a8c5d136f8594506f5a573 100644 (file)
@@ -51,11 +51,13 @@ class Log {
      * @return          The newly created concrete Log instance, or an
      *                  false on an error.
      */
-    function factory ($log_type, $log_name = '', $ident = '', $conf = array()) {
+    function &factory($log_type, $log_name = '', $ident = '', $conf = array())
+    {
         $log_type = strtolower($log_type);
         $classfile = 'Log/' . $log_type . '.php';
-       if (@include_once $classfile) {
-            $class = 'Log_' . $log_type;
+        @include_once $classfile;
+        $class = 'Log_' . $log_type;
+        if (class_exists($class)) {
             return new $class($log_name, $ident, $conf);
         } else {
             return false;
@@ -101,7 +103,7 @@ class Log {
         
         $signature = md5($log_type . '][' . $log_name . '][' . $ident . '][' . implode('][', $conf));
         if (!isset($instances[$signature])) {
-            $instances[$signature] = Log::factory($log_type, $log_name, $ident, $conf);
+            $instances[$signature] = &Log::factory($log_type, $log_name, $ident, $conf);
         }
         return $instances[$signature];
     }