mirror of
https://github.com/php/php-src.git
synced 2024-09-22 10:27:25 +00:00
Fix error handling selection when both class and global are set
This commit is contained in:
parent
85106b82e9
commit
409a631bed
@ -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);
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user