summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas V.V.Cox <cox@php.net>2002-03-13 01:17:47 +0000
committerTomas V.V.Cox <cox@php.net>2002-03-13 01:17:47 +0000
commit409a631bed28a34dc1d44dfb8ad9ac9cdd26cdf8 (patch)
tree3cc496c6be6e126af992692d0d664c3011a9cee5
parent85106b82e92240b59c06db03a269b7760f4ebd32 (diff)
downloadphp-git-409a631bed28a34dc1d44dfb8ad9ac9cdd26cdf8.tar.gz
Fix error handling selection when both class and global are set
-rw-r--r--pear/PEAR.php47
-rw-r--r--pear/tests/pear_error3.phpt16
2 files changed, 21 insertions, 42 deletions
diff --git a/pear/PEAR.php b/pear/PEAR.php
index db7f21bfa7..f254e38709 100644
--- a/pear/PEAR.php
+++ b/pear/PEAR.php
@@ -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);
diff --git a/pear/tests/pear_error3.phpt b/pear/tests/pear_error3.phpt
index 694d877519..fb26c9a2b0 100644
--- a/pear/tests/pear_error3.phpt
+++ b/pear/tests/pear_error3.phpt
@@ -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