$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();
//
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) {
$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)) {
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);
}
}
+// 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