cvs: php4 /pear PEAR.php
| From: | Thomas V.V.Cox | Date: | Sun, 29 Jul 2001 03:46:55 +0000 |
| Subject: | cvs: php4 /pear PEAR.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-368@lists.php.net to get a copy of this message | ||
cox Sat Jul 28 23:46:55 2001 EDT
Modified files:
/php4/pear PEAR.php
Log:
Added the methods pushErrorHandler and popErrorHandler. With this it's
posible to override the actual error handler with a new one for the time
you need and restore it back when finish.
Index: php4/pear/PEAR.php
diff -u php4/pear/PEAR.php:1.7 php4/pear/PEAR.php:1.8
--- php4/pear/PEAR.php:1.7 Sat Jul 7 11:54:27 2001
+++ php4/pear/PEAR.php Sat Jul 28 23:46:55 2001
@@ -17,7 +17,7 @@
// | Stig Bakken <ssb@fast.no> |
// +----------------------------------------------------------------------+
//
-// $Id: PEAR.php,v 1.7 2001/07/07 15:54:27 mj Exp $
+// $Id: PEAR.php,v 1.8 2001/07/29 03:46:55 cox Exp $
//
define('PEAR_ERROR_RETURN', 1);
@@ -111,7 +111,7 @@
* Destructor (the emulated type of...). Does nothing right now,
* but is included for forward compatibility, so subclass
* destructors should always call it.
- *
+ *
* See the note in the class desciption about output from
* destructors.
*
@@ -176,7 +176,7 @@
* @since PHP 4.0.5
*/
- function setErrorHandling($mode, $options = null)
+ function setErrorHandling($mode = null, $options = null)
{
if (isset($this)) {
$setmode = &$this->_default_error_mode;
@@ -208,7 +208,7 @@
trigger_error("invalid error callback", E_USER_WARNING);
}
break;
-
+
default:
trigger_error("invalid error mode", E_USER_WARNING);
break;
@@ -310,6 +310,70 @@
}
// }}}
+
+ /**
+ * Push a new error handler on top of the error handler options stack. With this
+ * you can easely override the actual error handler for some code and restore
+ * it later with popErrorHandling.
+ *
+ * @param $mode mixed (same as setErrorHandling)
+ * @param $options mixed (same as setErrorHandling)
+ *
+ * @return bool Always true
+ *
+ * @see PEAR::setErrorHandling
+ */
+ function pushErrorHandling($mode, $options = null)
+ {
+ $stack = &$GLOBALS['_PEAR_error_handler_stack'];
+ if (!is_array($stack)) {
+ 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'];
+ }
+ if (!isset($def_mode)) {
+ $def_mode = PEAR_ERROR_RETURN;
+ }
+ $stack = array();
+ $stack[] = array($def_mode, $def_options);
+ }
+
+ if (isset($this)) {
+ $this->setErrorHandling($mode, $options);
+ } else {
+ PEAR::setErrorHandling($mode, $options);
+ }
+ $stack[] = array($mode, $options);
+ return true;
+ }
+
+ /**
+ * Pop the last error handler used
+ *
+ * @return bool Always true
+ *
+ * @see PEAR::pushErrorHandling
+ */
+ function popErrorHandling()
+ {
+ $stack = &$GLOBALS['_PEAR_error_handler_stack'];
+ array_pop($stack);
+ list($mode, $options) = $stack[sizeof($stack) - 1];
+ if (isset($this)) {
+ $this->setErrorHandling($mode, $options);
+ } else {
+ PEAR::setErrorHandling($mode, $options);
+ }
+ return true;
+ }
+
}
// {{{ _PEAR_call_destructors()
@@ -357,7 +421,7 @@
// Wait until we have a stack-groping function in PHP.
//var $file = '';
//var $line = 0;
-
+
// }}}
// {{{ constructor
@@ -456,7 +520,7 @@
// }}}
// {{{ getMessage()
-
+
/**
* Get the error message from an error object.
*
@@ -468,11 +532,11 @@
return ($this->error_prepend . $this->error_message_prefix .
$this->message . $this->error_append);
}
-
+
// }}}
// {{{ getCode()
-
+
/**
* Get error code from an error object
*