|
From: Ulf E. <ulf...@us...> - 2005-05-24 20:46:12
|
Update of /cvsroot/phpbt/phpbt/inc/pear In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15519 Modified Files: PEAR.php Log Message: Update to PEAR 1.3.5 Index: PEAR.php =================================================================== RCS file: /cvsroot/phpbt/phpbt/inc/pear/PEAR.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PEAR.php 13 Sep 2002 18:07:51 -0000 1.1 +++ PEAR.php 24 May 2005 20:45:59 -0000 1.2 @@ -1,31 +1,38 @@ <?php // -// +----------------------------------------------------------------------+ -// | PHP Version 4 | -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2002 The PHP Group | -// +----------------------------------------------------------------------+ -// | This source file is subject to version 2.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | http://www.php.net/license/2_02.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | li...@ph... so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Authors: Sterling Hughes <ste...@ph...> | -// | Stig Bakken <ss...@fa...> | -// | Tomas V.V.Cox <co...@id...> | -// +----------------------------------------------------------------------+ +// +--------------------------------------------------------------------+ +// | PEAR, the PHP Extension and Application Repository | +// +--------------------------------------------------------------------+ +// | Copyright (c) 1997-2004 The PHP Group | +// +--------------------------------------------------------------------+ +// | This source file is subject to version 3.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available through the world-wide-web at the following url: | +// | http://www.php.net/license/3_0.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | li...@ph... so we can mail you a copy immediately. | +// +--------------------------------------------------------------------+ +// | Authors: Sterling Hughes <ste...@ph...> | +// | Stig Bakken <ss...@ph...> | +// | Tomas V.V.Cox <co...@id...> | +// +--------------------------------------------------------------------+ // // $Id$ // -define('PEAR_ERROR_RETURN', 1); -define('PEAR_ERROR_PRINT', 2); -define('PEAR_ERROR_TRIGGER', 4); -define('PEAR_ERROR_DIE', 8); -define('PEAR_ERROR_CALLBACK', 16); +define('PEAR_ERROR_RETURN', 1); +define('PEAR_ERROR_PRINT', 2); +define('PEAR_ERROR_TRIGGER', 4); +define('PEAR_ERROR_DIE', 8); +define('PEAR_ERROR_CALLBACK', 16); +/** + * WARNING: obsolete + * @deprecated + */ +define('PEAR_ERROR_EXCEPTION', 32); +define('PEAR_ZE2', (function_exists('version_compare') && + version_compare(zend_version(), "2-dev", "ge"))); if (substr(PHP_OS, 0, 3) == 'WIN') { define('OS_WINDOWS', true); @@ -37,14 +44,22 @@ define('PEAR_OS', 'Unix'); // blatant assumption } +// instant backwards compatibility +if (!defined('PATH_SEPARATOR')) { + if (OS_WINDOWS) { + define('PATH_SEPARATOR', ';'); + } else { + define('PATH_SEPARATOR', ':'); + } +} + $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(); +$GLOBALS['_PEAR_shutdown_funcs'] = array(); +$GLOBALS['_PEAR_error_handler_stack'] = array(); -// -// Tests needed: - PEAR inheritance -// +@ini_set('track_errors', true); /** * Base class for other PEAR classes. Provides rudimentary @@ -60,8 +75,12 @@ * discarded. If you need to get any debug information from your * destructor, use error_log(), syslog() or something similar. * + * IMPORTANT! To use the emulated destructors you need to create the + * objects by reference: $obj =& new PEAR_child; + * * @since PHP 4.0.2 - * @author Stig Bakken <ss...@fa...> + * @author Stig Bakken <ss...@ph...> + * @see http://pear.php.net/manual/ */ class PEAR { @@ -126,25 +145,29 @@ * $_PEAR_destructor_object_list for destructor emulation if a * destructor object exists. * - * @param string (optional) which class to use for error objects, - * defaults to PEAR_Error. + * @param string $error_class (optional) which class to use for + * error objects, defaults to PEAR_Error. * @access public * @return void */ function PEAR($error_class = null) { - $classname = get_class($this); + $classname = strtolower(get_class($this)); if ($this->_debug) { print "PEAR constructor called, class=$classname\n"; } if ($error_class !== null) { $this->_error_class = $error_class; } - while ($classname) { + while ($classname && strcasecmp($classname, "pear")) { $destructor = "_$classname"; if (method_exists($this, $destructor)) { global $_PEAR_destructor_object_list; $_PEAR_destructor_object_list[] = &$this; + if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) { + register_shutdown_function("_PEAR_call_destructors"); + $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true; + } break; } else { $classname = get_parent_class($classname); @@ -168,31 +191,81 @@ */ function _PEAR() { if ($this->_debug) { - printf("PEAR destructor called, class=%s\n", get_class($this)); + printf("PEAR destructor called, class=%s\n", strtolower(get_class($this))); } } // }}} + // {{{ getStaticProperty() + + /** + * If you have a class that's mostly/entirely static, and you need static + * properties, you can use this method to simulate them. Eg. in your method(s) + * do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar'); + * You MUST use a reference, or they will not persist! + * + * @access public + * @param string $class The calling classname, to prevent clashes + * @param string $var The variable to retrieve. + * @return mixed A reference to the variable. If not set it will be + * auto initialised to NULL. + */ + function &getStaticProperty($class, $var) + { + static $properties; + return $properties[$class][$var]; + } + + // }}} + // {{{ registerShutdownFunc() + + /** + * Use this function to register a shutdown method for static + * classes. + * + * @access public + * @param mixed $func The function name (or array of class/method) to call + * @param mixed $args The arguments to pass to the function + * @return void + */ + function registerShutdownFunc($func, $args = array()) + { + $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args); + } + + // }}} // {{{ isError() /** * Tell whether a value is a PEAR error. * - * @param mixed the value to test + * @param mixed $data the value to test + * @param int $code if $data is an error object, return true + * only if $code is a string and + * $obj->getMessage() == $code or + * $code is an integer and $obj->getCode() == $code * @access public * @return bool true if parameter is an error */ - function isError($data) { - return (bool)(is_object($data) && - (get_class($data) == 'pear_error' || - is_subclass_of($data, 'pear_error'))); + function isError($data, $code = null) + { + if (is_a($data, 'PEAR_Error')) { + if (is_null($code)) { + return true; + } elseif (is_string($code)) { + return $data->getMessage() == $code; + } else { + return $data->getCode() == $code; + } + } + return false; } // }}} // {{{ setErrorHandling() /** - * Sets how errors generated by this DB object should be handled. + * Sets how errors generated by this object should be handled. * Can be invoked both in objects and statically. If called * statically, setErrorHandling sets the default behaviour for all * PEAR objects. If called in an object, setErrorHandling sets @@ -200,8 +273,8 @@ * * @param int $mode * One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT, - * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE or - * PEAR_ERROR_CALLBACK. + * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE, + * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION. * * @param mixed $options * When $mode is PEAR_ERROR_TRIGGER, this is the error level (one @@ -225,23 +298,23 @@ * @see PEAR_ERROR_TRIGGER * @see PEAR_ERROR_DIE * @see PEAR_ERROR_CALLBACK + * @see PEAR_ERROR_EXCEPTION * * @since PHP 4.0.5 */ function setErrorHandling($mode = null, $options = null) { - if (isset($this)) { + if (isset($this) && is_a($this, 'PEAR')) { $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) { + case PEAR_ERROR_EXCEPTION: case PEAR_ERROR_RETURN: case PEAR_ERROR_PRINT: case PEAR_ERROR_TRIGGER: @@ -253,9 +326,8 @@ case PEAR_ERROR_CALLBACK: $setmode = $mode; - if ((is_string($options) && function_exists($options)) || - (is_array($options) && method_exists(@$options[0], @$options[1]))) - { + // class/object method callback + if (is_callable($options)) { $setoptions = $options; } else { trigger_error("invalid error callback", E_USER_WARNING); @@ -279,12 +351,14 @@ * expected errors are in effect until they are popped off the * stack with the popExpect() method. * - * @param mixed a single error code or an array of error codes - * to expect + * Note that this method can not be called statically + * + * @param mixed $code a single error code or an array of error codes to expect * * @return int the new depth of the "expected errors" stack + * @access public */ - function expectError($code = "*") + function expectError($code = '*') { if (is_array($code)) { array_push($this->_expected_errors, $code); @@ -309,6 +383,76 @@ } // }}} + // {{{ _checkDelExpect() + + /** + * This method checks unsets an error code if available + * + * @param mixed error code + * @return bool true if the error code was unset, false otherwise + * @access private + * @since PHP 4.3.0 + */ + function _checkDelExpect($error_code) + { + $deleted = false; + + foreach ($this->_expected_errors AS $key => $error_array) { + if (in_array($error_code, $error_array)) { + unset($this->_expected_errors[$key][array_search($error_code, $error_array)]); + $deleted = true; + } + + // clean up empty arrays + if (0 == count($this->_expected_errors[$key])) { + unset($this->_expected_errors[$key]); + } + } + return $deleted; + } + + // }}} + // {{{ delExpect() + + /** + * This method deletes all occurences of the specified element from + * the expected error codes stack. + * + * @param mixed $error_code error code that should be deleted + * @return mixed list of error codes that were deleted or error + * @access public + * @since PHP 4.3.0 + */ + function delExpect($error_code) + { + $deleted = false; + + if ((is_array($error_code) && (0 != count($error_code)))) { + // $error_code is a non-empty array here; + // we walk through it trying to unset all + // values + foreach($error_code as $key => $error) { + if ($this->_checkDelExpect($error)) { + $deleted = true; + } else { + $deleted = false; + } + } + return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME + } elseif (!empty($error_code)) { + // $error_code comes alone, trying to unset it + if ($this->_checkDelExpect($error_code)) { + return true; + } else { + return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME + } + } else { + // $error_code is empty + return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME + } + } + + // }}} // {{{ raiseError() /** @@ -317,16 +461,16 @@ * handling applied. If the $mode and $options parameters are not * specified, the object's defaults are used. * - * @param $message a text error message or a PEAR error object + * @param mixed $message a text error message or a PEAR error object * - * @param $code a numeric error code (it is up to your class + * @param int $code a numeric error code (it is up to your class * to define these if you want to use codes) * - * @param $mode One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT, - * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE or - * PEAR_ERROR_CALLBACK. + * @param int $mode One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT, + * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE, + * PEAR_ERROR_CALLBACK, PEAR_ERROR_EXCEPTION. * - * @param $options If $mode is PEAR_ERROR_TRIGGER, this parameter + * @param mixed $options If $mode is PEAR_ERROR_TRIGGER, this parameter * specifies the PHP-internal error level (one of * E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR). * If $mode is PEAR_ERROR_CALLBACK, this @@ -334,13 +478,13 @@ * method. In other error modes this parameter * is ignored. * - * @param $userinfo If you need to pass along for example debug + * @param string $userinfo If you need to pass along for example debug * information, this parameter is meant for that. * - * @param $error_class The returned error object will be instantiated - * from this class, if specified. + * @param string $error_class The returned error object will be + * instantiated from this class, if specified. * - * @param $skipmsg If true, raiseError will only pass error codes, + * @param bool $skipmsg If true, raiseError will only pass error codes, * the error message parameter will be dropped. * * @access public @@ -348,7 +492,7 @@ * @see PEAR::setErrorHandling * @since PHP 4.0.5 */ - function &raiseError($message = null, + function raiseError($message = null, $code = null, $mode = null, $options = null, @@ -361,6 +505,7 @@ $code = $message->getCode(); $userinfo = $message->getUserInfo(); $error_class = $message->getType(); + $message->error_message_prefix = ''; $message = $message->getMessage(); } @@ -371,47 +516,19 @@ $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)) { - if (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)) { @@ -427,40 +544,125 @@ } // }}} + // {{{ throwError() + + /** + * Simpler form of raiseError with fewer options. In most cases + * message, code and userinfo are enough. + * + * @param string $message + * + */ + function throwError($message = null, + $code = null, + $userinfo = null) + { + if (isset($this) && is_a($this, 'PEAR')) { + return $this->raiseError($message, $code, null, null, $userinfo); + } else { + return PEAR::raiseError($message, $code, null, null, $userinfo); + } + } + + // }}} + function staticPushErrorHandling($mode, $options = null) + { + $stack = &$GLOBALS['_PEAR_error_handler_stack']; + $def_mode = &$GLOBALS['_PEAR_default_error_mode']; + $def_options = &$GLOBALS['_PEAR_default_error_options']; + $stack[] = array($def_mode, $def_options); + switch ($mode) { + case PEAR_ERROR_EXCEPTION: + case PEAR_ERROR_RETURN: + case PEAR_ERROR_PRINT: + case PEAR_ERROR_TRIGGER: + case PEAR_ERROR_DIE: + case null: + $def_mode = $mode; + $def_options = $options; + break; + + case PEAR_ERROR_CALLBACK: + $def_mode = $mode; + // class/object method callback + if (is_callable($options)) { + $def_options = $options; + } else { + trigger_error("invalid error callback", E_USER_WARNING); + } + break; + + default: + trigger_error("invalid error mode", E_USER_WARNING); + break; + } + $stack[] = array($mode, $options); + return true; + } + + function staticPopErrorHandling() + { + $stack = &$GLOBALS['_PEAR_error_handler_stack']; + $setmode = &$GLOBALS['_PEAR_default_error_mode']; + $setoptions = &$GLOBALS['_PEAR_default_error_options']; + array_pop($stack); + list($mode, $options) = $stack[sizeof($stack) - 1]; + array_pop($stack); + switch ($mode) { + case PEAR_ERROR_EXCEPTION: + case PEAR_ERROR_RETURN: + case PEAR_ERROR_PRINT: + case PEAR_ERROR_TRIGGER: + case PEAR_ERROR_DIE: + case null: + $setmode = $mode; + $setoptions = $options; + break; + + case PEAR_ERROR_CALLBACK: + $setmode = $mode; + // class/object method callback + if (is_callable($options)) { + $setoptions = $options; + } else { + trigger_error("invalid error callback", E_USER_WARNING); + } + break; + + default: + trigger_error("invalid error mode", E_USER_WARNING); + break; + } + return true; + } + // {{{ pushErrorHandling() /** - * Push a new error handler on top of the error handler options stack. With this - * you can easily 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 - */ + * Push a new error handler on top of the error handler options stack. With this + * you can easily override the actual error handler for some code and restore + * it later with popErrorHandling. + * + * @param mixed $mode (same as setErrorHandling) + * @param mixed $options (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']; - } - $stack = array(); - $stack[] = array($def_mode, $def_options); + if (isset($this) && is_a($this, 'PEAR')) { + $def_mode = &$this->_default_error_mode; + $def_options = &$this->_default_error_options; + } else { + $def_mode = &$GLOBALS['_PEAR_default_error_mode']; + $def_options = &$GLOBALS['_PEAR_default_error_options']; } + $stack[] = array($def_mode, $def_options); - if (isset($this)) { + if (isset($this) && is_a($this, 'PEAR')) { $this->setErrorHandling($mode, $options); } else { PEAR::setErrorHandling($mode, $options); @@ -484,7 +686,8 @@ $stack = &$GLOBALS['_PEAR_error_handler_stack']; array_pop($stack); list($mode, $options) = $stack[sizeof($stack) - 1]; - if (isset($this)) { + array_pop($stack); + if (isset($this) && is_a($this, 'PEAR')) { $this->setErrorHandling($mode, $options); } else { PEAR::setErrorHandling($mode, $options); @@ -493,6 +696,39 @@ } // }}} + // {{{ loadExtension() + + /** + * OS independant PHP extension load. Remember to take care + * on the correct extension name for case sensitive OSes. + * + * @param string $ext The extension name + * @return bool Success or not on the dl() call + */ + function loadExtension($ext) + { + if (!extension_loaded($ext)) { + // if either returns true dl() will produce a FATAL error, stop that + if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) { + return false; + } + if (OS_WINDOWS) { + $suffix = '.dll'; + } elseif (PHP_OS == 'HP-UX') { + $suffix = '.sl'; + } elseif (PHP_OS == 'AIX') { + $suffix = '.a'; + } elseif (PHP_OS == 'OSX') { + $suffix = '.bundle'; + } else { + $suffix = '.so'; + } + return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix); + } + return true; + } + + // }}} } // {{{ _PEAR_call_destructors() @@ -504,6 +740,9 @@ sizeof($_PEAR_destructor_object_list)) { reset($_PEAR_destructor_object_list); + if (@PEAR::getStaticProperty('PEAR', 'destructlifo')) { + $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list); + } while (list($k, $objref) = each($_PEAR_destructor_object_list)) { $classname = get_class($objref); while ($classname) { @@ -520,6 +759,13 @@ // not called more than once. $_PEAR_destructor_object_list = array(); } + + // Now call the shutdown functions + if (is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) { + foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) { + call_user_func_array($value[0], $value[1]); + } + } } // }}} @@ -534,11 +780,7 @@ var $code = -1; var $message = ''; var $userinfo = ''; - - // Wait until we have a stack-groping function in PHP. - //var $file = ''; - //var $line = 0; - + var $backtrace = null; // }}} // {{{ constructor @@ -546,18 +788,20 @@ /** * PEAR_Error constructor * - * @param $message error message + * @param string $message message * - * @param $code (optional) error code + * @param int $code (optional) error code * - * @param $mode (optional) error mode, one of: PEAR_ERROR_RETURN, - * PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER or - * PEAR_ERROR_CALLBACK + * @param int $mode (optional) error mode, one of: PEAR_ERROR_RETURN, + * PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER, + * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION * - * @param $level (optional) error level, _OR_ in the case of + * @param mixed $options (optional) error level, _OR_ in the case of * PEAR_ERROR_CALLBACK, the callback function or object/method * tuple. * + * @param string $userinfo (optional) additional user/debug info + * * @access public * */ @@ -571,6 +815,11 @@ $this->code = $code; $this->mode = $mode; $this->userinfo = $userinfo; + if (function_exists("debug_backtrace")) { + if (@!PEAR::getStaticProperty('PEAR_Error', 'skiptrace')) { + $this->backtrace = debug_backtrace(); + } + } if ($mode & PEAR_ERROR_CALLBACK) { $this->level = E_USER_NOTICE; $this->callback = $options; @@ -605,17 +854,14 @@ die(sprintf($format, $msg)); } if ($this->mode & PEAR_ERROR_CALLBACK) { - if (is_string($this->callback) && strlen($this->callback)) { + if (is_callable($this->callback)) { call_user_func($this->callback, $this); - } elseif (is_array($this->callback) && - sizeof($this->callback) == 2 && - is_object($this->callback[0]) && - is_string($this->callback[1]) && - strlen($this->callback[1])) { - @call_user_method($this->callback[1], $this->callback[0], - $this); } } + if ($this->mode & PEAR_ERROR_EXCEPTION) { + trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_ErrorStack for exceptions", E_USER_WARNING); + eval('$e = new Exception($this->message, $this->code);$e->PEAR_Error = $this;throw($e);'); + } } // }}} @@ -654,7 +900,7 @@ * @return string full error message * @access public */ - function getMessage () + function getMessage() { return ($this->error_message_prefix . $this->message); } @@ -683,7 +929,7 @@ * @return string error/exception name (type) * @access public */ - function getType () + function getType() { return get_class($this); } @@ -697,7 +943,7 @@ * @return string user-supplied information * @access public */ - function getUserInfo () + function getUserInfo() { return $this->userinfo; } @@ -711,12 +957,31 @@ * @return string debug information * @access public */ - function getDebugInfo () + function getDebugInfo() { return $this->getUserInfo(); } // }}} + // {{{ getBacktrace() + + /** + * Get the call backtrace from where the error was generated. + * Supported with PHP 4.3.0 or newer. + * + * @param int $frame (optional) what frame to fetch + * @return array Backtrace, or NULL if not available. + * @access public + */ + function getBacktrace($frame = null) + { + if ($frame === null) { + return $this->backtrace; + } + return $this->backtrace[$frame]; + } + + // }}} // {{{ addUserInfo() function addUserInfo($info) @@ -744,20 +1009,19 @@ E_USER_ERROR => 'error'); if ($this->mode & PEAR_ERROR_CALLBACK) { if (is_array($this->callback)) { - $callback = get_class($this->callback[0]) . '::' . + $callback = (is_object($this->callback[0]) ? + strtolower(get_class($this->callback[0])) : + $this->callback[0]) . '::' . $this->callback[1]; } else { $callback = $this->callback; } return sprintf('[%s: message="%s" code=%d mode=callback '. 'callback=%s prefix="%s" info="%s"]', - get_class($this), $this->message, $this->code, + strtolower(get_class($this)), $this->message, $this->code, $callback, $this->error_message_prefix, $this->userinfo); } - if ($this->mode & PEAR_ERROR_CALLBACK) { - $modes[] = 'callback'; - } if ($this->mode & PEAR_ERROR_PRINT) { $modes[] = 'print'; } @@ -772,7 +1036,7 @@ } return sprintf('[%s: message="%s" code=%d mode=%s level=%s '. 'prefix="%s" info="%s"]', - get_class($this), $this->message, $this->code, + strtolower(get_class($this)), $this->message, $this->code, implode("|", $modes), $levels[$this->level], $this->error_message_prefix, $this->userinfo); @@ -781,8 +1045,6 @@ // }}} } -register_shutdown_function("_PEAR_call_destructors"); - /* * Local Variables: * mode: php |