]> granicus.if.org Git - php/commitdiff
Fix error handling selection when both class and global are set
authorTomas V.V.Cox <cox@php.net>
Wed, 13 Mar 2002 01:17:47 +0000 (01:17 +0000)
committerTomas V.V.Cox <cox@php.net>
Wed, 13 Mar 2002 01:17:47 +0000 (01:17 +0000)
pear/PEAR.php
pear/tests/pear_error3.phpt

index db7f21bfa71a7b6525e0dab6e806a991ad75a51a..f254e3870995d9190e6151a0caa4da4a49ab266b 100644 (file)
@@ -39,7 +39,6 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
 
 $GLOBALS['_PEAR_default_error_mode']     = PEAR_ERROR_RETURN;
 $GLOBALS['_PEAR_default_error_options']  = E_USER_NOTICE;
-$GLOBALS['_PEAR_default_error_callback'] = '';
 $GLOBALS['_PEAR_destructor_object_list'] = array();
 
 //
@@ -234,11 +233,9 @@ class PEAR
         if (isset($this)) {
             $setmode     = &$this->_default_error_mode;
             $setoptions  = &$this->_default_error_options;
-            //$setcallback = &$this->_default_error_callback;
         } else {
             $setmode     = &$GLOBALS['_PEAR_default_error_mode'];
             $setoptions  = &$GLOBALS['_PEAR_default_error_options'];
-            //$setcallback = &$GLOBALS['_PEAR_default_error_callback'];
         }
 
         switch ($mode) {
@@ -371,45 +368,19 @@ class PEAR
                 $mode = PEAR_ERROR_RETURN;
             }
         }
-
+        // No mode given, try global ones
         if ($mode === null) {
+            // Class error handler
             if (isset($this) && isset($this->_default_error_mode)) {
-                $mode = $this->_default_error_mode;
-            } else {
-                $mode = $GLOBALS['_PEAR_default_error_mode'];
-            }
-        }
-
-        if ($mode == PEAR_ERROR_TRIGGER && $options === null) {
-            if (isset($this)) {
-                if (isset($this->_default_error_options)) {
-                    $options = $this->_default_error_options;
-                }
-            } else {
+                $mode    = $this->_default_error_mode;
+                $options = $this->_default_error_options;
+            // Global error handler
+            } elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
+                $mode    = $GLOBALS['_PEAR_default_error_mode'];
                 $options = $GLOBALS['_PEAR_default_error_options'];
             }
         }
 
-        if ($mode == PEAR_ERROR_CALLBACK) {
-            if (!is_string($options) &&
-                !(is_array($options) && sizeof($options) == 2 &&
-                  is_object($options[0]) && is_string($options[1])))
-            {
-                if (isset($this) && isset($this->_default_error_options)) {
-                    $options = $this->_default_error_options;
-                } else {
-                    $options = $GLOBALS['_PEAR_default_error_options'];
-                }
-            }
-        } else {
-            if ($options === null) {
-                if (isset($this) && isset($this->_default_error_options)) {
-                    $options = $this->_default_error_options;
-                } else {
-                    $options = $GLOBALS['_PEAR_default_error_options'];
-                }
-            }
-        }
         if ($error_class !== null) {
             $ec = $error_class;
         } elseif (isset($this) && isset($this->_error_class)) {
@@ -446,13 +417,9 @@ class PEAR
             if (isset($this)) {
                 $def_mode = &$this->_default_error_mode;
                 $def_options = &$this->_default_error_options;
-                // XXX Used anywhere?
-                //$def_callback = &$this->_default_error_callback;
             } else {
                 $def_mode = &$GLOBALS['_PEAR_default_error_mode'];
                 $def_options = &$GLOBALS['_PEAR_default_error_options'];
-                // XXX Used anywhere?
-                //$def_callback = &$GLOBALS['_PEAR_default_error_callback'];
             }
             $stack = array();
             $stack[] = array($def_mode, $def_options);
index 694d877519e5f2b6ec7534dfb3e032e041d8ac99..fb26c9a2b01594998e04a4909dd56cc6557271d6 100644 (file)
@@ -22,19 +22,31 @@ function errorhandler($eobj)
     }
 }
 
+// Test 1
+PEAR::setErrorHandling(PEAR_ERROR_PRINT, "OOPS: %s\n");
+$tmp = new PEAR;
+$tmp->raiseError("error happens");
+
+// Return PEAR to its original state
+$GLOBALS['_PEAR_default_error_mode']     = PEAR_ERROR_RETURN;
+$GLOBALS['_PEAR_default_error_options']  = E_USER_NOTICE;
+$GLOBALS['_PEAR_default_error_callback'] = '';
+
+// Test 2
 $obj = new PEAR;
 $obj->setErrorHandling(PEAR_ERROR_PRINT);
 $obj->raiseError("error 1\n");
 $obj->setErrorHandling(null);
 $obj->raiseError("error 2\n");
 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "errorhandler");
-$obj->raiseError("error 3\n");
+$obj->raiseError("error 3");
 $obj->setErrorHandling(PEAR_ERROR_PRINT);
 $obj->raiseError("error 4\n");
 
 ?>
 --EXPECT--
+OOPS: error happens
 error 1
 errorhandler called with an error object.
 error message: error 3
-error 4
+error 4
\ No newline at end of file