3 * PEAR, the PHP Extension and Application Repository
5 * PEAR class and PEAR_Error class
11 * @author Sterling Hughes <sterling@php.net>
12 * @author Stig Bakken <ssb@php.net>
13 * @author Tomas V.V.Cox <cox@idecnet.com>
14 * @author Greg Beaver <cellog@php.net>
15 * @copyright 1997-2010 The Authors
16 * @license http://opensource.org/licenses/bsd-license.php New BSD License
17 * @link http://pear.php.net/package/PEAR
18 * @since File available since Release 0.1
24 define('PEAR_ERROR_RETURN', 1);
25 define('PEAR_ERROR_PRINT', 2);
26 define('PEAR_ERROR_TRIGGER', 4);
27 define('PEAR_ERROR_DIE', 8);
28 define('PEAR_ERROR_CALLBACK', 16);
33 define('PEAR_ERROR_EXCEPTION', 32);
36 if (substr(PHP_OS, 0, 3) == 'WIN') {
37 define('OS_WINDOWS', true);
38 define('OS_UNIX', false);
39 define('PEAR_OS', 'Windows');
41 define('OS_WINDOWS', false);
42 define('OS_UNIX', true);
43 define('PEAR_OS', 'Unix'); // blatant assumption
46 $GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_RETURN;
47 $GLOBALS['_PEAR_default_error_options'] = E_USER_NOTICE;
48 $GLOBALS['_PEAR_destructor_object_list'] = array();
49 $GLOBALS['_PEAR_shutdown_funcs'] = array();
50 $GLOBALS['_PEAR_error_handler_stack'] = array();
52 @ini_set('track_errors', true);
55 * Base class for other PEAR classes. Provides rudimentary
56 * emulation of destructors.
58 * If you want a destructor in your class, inherit PEAR and make a
59 * destructor method called _yourclassname (same name as the
60 * constructor, but with a "_" prefix). Also, in your constructor you
61 * have to call the PEAR constructor: $this->PEAR();.
62 * The destructor method will be called without parameters. Note that
63 * at in some SAPI implementations (such as Apache), any output during
64 * the request shutdown (in which destructors are called) seems to be
65 * discarded. If you need to get any debug information from your
66 * destructor, use error_log(), syslog() or something similar.
68 * IMPORTANT! To use the emulated destructors you need to create the
69 * objects by reference: $obj =& new PEAR_child;
73 * @author Stig Bakken <ssb@php.net>
74 * @author Tomas V.V. Cox <cox@idecnet.com>
75 * @author Greg Beaver <cellog@php.net>
76 * @copyright 1997-2006 The PHP Group
77 * @license http://opensource.org/licenses/bsd-license.php New BSD License
78 * @version Release: @package_version@
79 * @link http://pear.php.net/package/PEAR
81 * @since Class available since PHP 4.0.2
82 * @link http://pear.php.net/manual/en/core.pear.php#core.pear.pear
87 * List of methods that can be called both statically and non-statically.
90 protected static $bivalentMethods = array(
91 'setErrorHandling' => true,
94 'pushErrorHandling' => true,
95 'popErrorHandling' => true,
98 * Whether to enable internal debug messages.
105 * Default error mode for this object.
110 var $_default_error_mode = null;
112 * Default error options used for this object when error mode
113 * is PEAR_ERROR_TRIGGER.
118 var $_default_error_options = null;
120 * Default error handler (callback) for this object, if error mode is
121 * PEAR_ERROR_CALLBACK.
126 var $_default_error_handler = '';
128 * Which class to use for error objects.
133 var $_error_class = 'PEAR_Error';
135 * An array of expected errors.
140 var $_expected_errors = array();
142 public static function __callStatic($method, $arguments)
144 if (!isset(self::$bivalentMethods[$method])) {
146 'Call to undefined method PEAR::' . $method . '()', E_USER_ERROR
149 return call_user_func_array(
150 array(get_class(), '_' . $method),
151 array_merge(array(null), $arguments)
156 * If you have a class that's mostly/entirely static, and you need static
157 * properties, you can use this method to simulate them. Eg. in your method(s)
158 * do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar');
159 * You MUST use a reference, or they will not persist!
161 * @param string $class The calling classname, to prevent clashes
162 * @param string $var The variable to retrieve.
163 * @return mixed A reference to the variable. If not set it will be
164 * auto initialised to NULL.
166 public static function &getStaticProperty($class, $var)
169 if (!isset($properties[$class])) {
170 $properties[$class] = array();
173 if (!array_key_exists($var, $properties[$class])) {
174 $properties[$class][$var] = null;
177 return $properties[$class][$var];
181 * Use this function to register a shutdown method for static
184 * @param mixed $func The function name (or array of class/method) to call
185 * @param mixed $args The arguments to pass to the function
189 public static function registerShutdownFunc($func, $args = array())
191 // if we are called statically, there is a potential
192 // that no shutdown func is registered. Bug #6445
193 if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
194 register_shutdown_function("_PEAR_call_destructors");
195 $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
197 $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
201 * Tell whether a value is a PEAR error.
203 * @param mixed $data the value to test
204 * @param int $code if $data is an error object, return true
205 * only if $code is a string and
206 * $obj->getMessage() == $code or
207 * $code is an integer and $obj->getCode() == $code
209 * @return bool true if parameter is an error
211 public static function isError($data, $code = null)
213 if (!is_a($data, 'PEAR_Error')) {
217 if (is_null($code)) {
219 } elseif (is_string($code)) {
220 return $data->getMessage() == $code;
223 return $data->getCode() == $code;
226 public static function staticPushErrorHandling($mode, $options = null)
228 $stack = &$GLOBALS['_PEAR_error_handler_stack'];
229 $def_mode = &$GLOBALS['_PEAR_default_error_mode'];
230 $def_options = &$GLOBALS['_PEAR_default_error_options'];
231 $stack[] = array($def_mode, $def_options);
233 case PEAR_ERROR_EXCEPTION:
234 case PEAR_ERROR_RETURN:
235 case PEAR_ERROR_PRINT:
236 case PEAR_ERROR_TRIGGER:
240 $def_options = $options;
243 case PEAR_ERROR_CALLBACK:
245 // class/object method callback
246 if (is_callable($options)) {
247 $def_options = $options;
249 trigger_error("invalid error callback", E_USER_WARNING);
254 trigger_error("invalid error mode", E_USER_WARNING);
257 $stack[] = array($mode, $options);
261 public static function staticPopErrorHandling()
263 $stack = &$GLOBALS['_PEAR_error_handler_stack'];
264 $setmode = &$GLOBALS['_PEAR_default_error_mode'];
265 $setoptions = &$GLOBALS['_PEAR_default_error_options'];
267 list($mode, $options) = $stack[sizeof($stack) - 1];
270 case PEAR_ERROR_EXCEPTION:
271 case PEAR_ERROR_RETURN:
272 case PEAR_ERROR_PRINT:
273 case PEAR_ERROR_TRIGGER:
277 $setoptions = $options;
280 case PEAR_ERROR_CALLBACK:
282 // class/object method callback
283 if (is_callable($options)) {
284 $setoptions = $options;
286 trigger_error("invalid error callback", E_USER_WARNING);
291 trigger_error("invalid error mode", E_USER_WARNING);
298 * OS independent PHP extension load. Remember to take care
299 * on the correct extension name for case sensitive OSes.
301 * @param string $ext The extension name
302 * @return bool Success or not on the dl() call
304 public static function loadExtension($ext)
306 if (extension_loaded($ext)) {
310 // if either returns true dl() will produce a FATAL error, stop that
312 function_exists('dl') === false ||
313 ini_get('enable_dl') != 1
320 } elseif (PHP_OS == 'HP-UX') {
322 } elseif (PHP_OS == 'AIX') {
324 } elseif (PHP_OS == 'OSX') {
330 return @dl('php_' . $ext . $suffix) || @dl($ext . $suffix);
334 * Sets how errors generated by this object should be handled.
335 * Can be invoked both in objects and statically. If called
336 * statically, setErrorHandling sets the default behaviour for all
337 * PEAR objects. If called in an object, setErrorHandling sets
338 * the default behaviour for that object.
340 * @param object $object
341 * Object the method was called on (non-static mode)
344 * One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
345 * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
346 * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION.
348 * @param mixed $options
349 * When $mode is PEAR_ERROR_TRIGGER, this is the error level (one
350 * of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
352 * When $mode is PEAR_ERROR_CALLBACK, this parameter is expected
353 * to be the callback function or method. A callback
354 * function is a string with the name of the function, a
355 * callback method is an array of two elements: the element
356 * at index 0 is the object, and the element at index 1 is
357 * the name of the method to call in the object.
359 * When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is
360 * a printf format string used when printing the error
365 * @see PEAR_ERROR_RETURN
366 * @see PEAR_ERROR_PRINT
367 * @see PEAR_ERROR_TRIGGER
368 * @see PEAR_ERROR_DIE
369 * @see PEAR_ERROR_CALLBACK
370 * @see PEAR_ERROR_EXCEPTION
374 protected static function _setErrorHandling(
375 $object, $mode = null, $options = null
378 if ($object !== null) {
379 $setmode = &$object->_default_error_mode;
380 $setoptions = &$object->_default_error_options;
382 $setmode = &$GLOBALS['_PEAR_default_error_mode'];
383 $setoptions = &$GLOBALS['_PEAR_default_error_options'];
387 case PEAR_ERROR_EXCEPTION:
388 case PEAR_ERROR_RETURN:
389 case PEAR_ERROR_PRINT:
390 case PEAR_ERROR_TRIGGER:
394 $setoptions = $options;
397 case PEAR_ERROR_CALLBACK:
399 // class/object method callback
400 if (is_callable($options)) {
401 $setoptions = $options;
403 trigger_error("invalid error callback", E_USER_WARNING);
408 trigger_error("invalid error mode", E_USER_WARNING);
414 * This method is a wrapper that returns an instance of the
415 * configured error class with this object's default error
416 * handling applied. If the $mode and $options parameters are not
417 * specified, the object's defaults are used.
420 * @param mixed $message a text error message or a PEAR error object
422 * @param int $code a numeric error code (it is up to your class
423 * to define these if you want to use codes)
425 * @param int $mode One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
426 * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
427 * PEAR_ERROR_CALLBACK, PEAR_ERROR_EXCEPTION.
429 * @param mixed $options If $mode is PEAR_ERROR_TRIGGER, this parameter
430 * specifies the PHP-internal error level (one of
431 * E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
432 * If $mode is PEAR_ERROR_CALLBACK, this
433 * parameter specifies the callback function or
434 * method. In other error modes this parameter
437 * @param string $userinfo If you need to pass along for example debug
438 * information, this parameter is meant for that.
440 * @param string $error_class The returned error object will be
441 * instantiated from this class, if specified.
443 * @param bool $skipmsg If true, raiseError will only pass error codes,
444 * the error message parameter will be dropped.
446 * @return object a PEAR error object
447 * @see PEAR::setErrorHandling
450 protected static function _raiseError($object,
459 // The error is yet a PEAR error object
460 if (is_object($message)) {
461 $code = $message->getCode();
462 $userinfo = $message->getUserInfo();
463 $error_class = $message->getType();
464 $message->error_message_prefix = '';
465 $message = $message->getMessage();
470 isset($object->_expected_errors) &&
471 count($object->_expected_errors) > 0 &&
472 count($exp = end($object->_expected_errors))
474 if ($exp[0] === "*" ||
475 (is_int(reset($exp)) && in_array($code, $exp)) ||
476 (is_string(reset($exp)) && in_array($message, $exp))
478 $mode = PEAR_ERROR_RETURN;
482 // No mode given, try global ones
483 if ($mode === null) {
484 // Class error handler
485 if ($object !== null && isset($object->_default_error_mode)) {
486 $mode = $object->_default_error_mode;
487 $options = $object->_default_error_options;
488 // Global error handler
489 } elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
490 $mode = $GLOBALS['_PEAR_default_error_mode'];
491 $options = $GLOBALS['_PEAR_default_error_options'];
495 if ($error_class !== null) {
497 } elseif ($object !== null && isset($object->_error_class)) {
498 $ec = $object->_error_class;
504 $a = new $ec($code, $mode, $options, $userinfo);
506 $a = new $ec($message, $code, $mode, $options, $userinfo);
513 * Simpler form of raiseError with fewer options. In most cases
514 * message, code and userinfo are enough.
517 * @param mixed $message a text error message or a PEAR error object
519 * @param int $code a numeric error code (it is up to your class
520 * to define these if you want to use codes)
522 * @param string $userinfo If you need to pass along for example debug
523 * information, this parameter is meant for that.
525 * @return object a PEAR error object
526 * @see PEAR::raiseError
528 protected static function _throwError($object, $message = null, $code = null, $userinfo = null)
530 if ($object !== null) {
531 $a = $object->raiseError($message, $code, null, null, $userinfo);
535 $a = PEAR::raiseError($message, $code, null, null, $userinfo);
540 * Push a new error handler on top of the error handler options stack. With this
541 * you can easily override the actual error handler for some code and restore
542 * it later with popErrorHandling.
545 * @param mixed $mode (same as setErrorHandling)
546 * @param mixed $options (same as setErrorHandling)
548 * @return bool Always true
550 * @see PEAR::setErrorHandling
552 protected static function _pushErrorHandling($object, $mode, $options = null)
554 $stack = &$GLOBALS['_PEAR_error_handler_stack'];
555 if ($object !== null) {
556 $def_mode = &$object->_default_error_mode;
557 $def_options = &$object->_default_error_options;
559 $def_mode = &$GLOBALS['_PEAR_default_error_mode'];
560 $def_options = &$GLOBALS['_PEAR_default_error_options'];
562 $stack[] = array($def_mode, $def_options);
564 if ($object !== null) {
565 $object->setErrorHandling($mode, $options);
567 PEAR::setErrorHandling($mode, $options);
569 $stack[] = array($mode, $options);
574 * Pop the last error handler used
577 * @return bool Always true
579 * @see PEAR::pushErrorHandling
581 protected static function _popErrorHandling($object)
583 $stack = &$GLOBALS['_PEAR_error_handler_stack'];
585 list($mode, $options) = $stack[sizeof($stack) - 1];
587 if ($object !== null) {
588 $object->setErrorHandling($mode, $options);
590 PEAR::setErrorHandling($mode, $options);
596 * Only here for backwards compatibility.
597 * E.g. Archive_Tar calls $this->PEAR() in its constructor.
599 * @param string $error_class Which class to use for error objects,
600 * defaults to PEAR_Error.
602 public function PEAR($error_class = null)
604 self::__construct($error_class);
608 * Constructor. Registers this object in
609 * $_PEAR_destructor_object_list for destructor emulation if a
610 * destructor object exists.
612 * @param string $error_class (optional) which class to use for
613 * error objects, defaults to PEAR_Error.
617 function __construct($error_class = null)
619 $classname = strtolower(get_class($this));
621 print "PEAR constructor called, class=$classname\n";
624 if ($error_class !== null) {
625 $this->_error_class = $error_class;
628 while ($classname && strcasecmp($classname, "pear")) {
629 $destructor = "_$classname";
630 if (method_exists($this, $destructor)) {
631 global $_PEAR_destructor_object_list;
632 $_PEAR_destructor_object_list[] = $this;
633 if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
634 register_shutdown_function("_PEAR_call_destructors");
635 $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
639 $classname = get_parent_class($classname);
645 * Destructor (the emulated type of...). Does nothing right now,
646 * but is included for forward compatibility, so subclass
647 * destructors should always call it.
649 * See the note in the class desciption about output from
658 printf("PEAR destructor called, class=%s\n", strtolower(get_class($this)));
662 public function __call($method, $arguments)
664 if (!isset(self::$bivalentMethods[$method])) {
666 'Call to undefined method PEAR::' . $method . '()', E_USER_ERROR
669 return call_user_func_array(
670 array(get_class(), '_' . $method),
671 array_merge(array($this), $arguments)
676 * This method is used to tell which errors you expect to get.
677 * Expected errors are always returned with error mode
678 * PEAR_ERROR_RETURN. Expected error codes are stored in a stack,
679 * and this method pushes a new element onto it. The list of
680 * expected errors are in effect until they are popped off the
681 * stack with the popExpect() method.
683 * Note that this method can not be called statically
685 * @param mixed $code a single error code or an array of error codes to expect
687 * @return int the new depth of the "expected errors" stack
690 function expectError($code = '*')
692 if (is_array($code)) {
693 array_push($this->_expected_errors, $code);
695 array_push($this->_expected_errors, array($code));
697 return count($this->_expected_errors);
701 * This method pops one element off the expected error codes
704 * @return array the list of error codes that were popped
708 return array_pop($this->_expected_errors);
712 * This method deletes all occurrences of the specified element from
713 * the expected error codes stack.
715 * @param mixed $error_code error code that should be deleted
716 * @return mixed list of error codes that were deleted or error
720 function delExpect($error_code)
723 if ((is_array($error_code) && (0 != count($error_code)))) {
724 // $error_code is a non-empty array here; we walk through it trying
725 // to unset all values
726 foreach ($error_code as $key => $error) {
727 $deleted = $this->_checkDelExpect($error) ? true : false;
730 return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
731 } elseif (!empty($error_code)) {
732 // $error_code comes alone, trying to unset it
733 if ($this->_checkDelExpect($error_code)) {
737 return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
740 // $error_code is empty
741 return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
745 * This method checks unsets an error code if available
747 * @param mixed error code
748 * @return bool true if the error code was unset, false otherwise
752 function _checkDelExpect($error_code)
755 foreach ($this->_expected_errors as $key => $error_array) {
756 if (in_array($error_code, $error_array)) {
757 unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
761 // clean up empty arrays
762 if (0 == count($this->_expected_errors[$key])) {
763 unset($this->_expected_errors[$key]);
771 function _PEAR_call_destructors()
773 global $_PEAR_destructor_object_list;
774 if (is_array($_PEAR_destructor_object_list) &&
775 sizeof($_PEAR_destructor_object_list)) {
776 reset($_PEAR_destructor_object_list);
778 $destructLifoExists = PEAR::getStaticProperty('PEAR', 'destructlifo');
780 if ($destructLifoExists) {
781 $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
784 foreach ($_PEAR_destructor_object_list as $k => $objref) {
785 $classname = get_class($objref);
787 $destructor = "_$classname";
788 if (method_exists($objref, $destructor)) {
789 $objref->$destructor();
792 $classname = get_parent_class($classname);
796 // Empty the object list to ensure that destructors are
797 // not called more than once.
798 $_PEAR_destructor_object_list = array();
801 // Now call the shutdown functions
803 isset($GLOBALS['_PEAR_shutdown_funcs']) &&
804 is_array($GLOBALS['_PEAR_shutdown_funcs']) &&
805 !empty($GLOBALS['_PEAR_shutdown_funcs'])
807 foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
808 call_user_func_array($value[0], $value[1]);
814 * Standard PEAR error class for PHP 4
816 * This class is supserseded by {@link PEAR_Exception} in PHP 5
820 * @author Stig Bakken <ssb@php.net>
821 * @author Tomas V.V. Cox <cox@idecnet.com>
822 * @author Gregory Beaver <cellog@php.net>
823 * @copyright 1997-2006 The PHP Group
824 * @license http://opensource.org/licenses/bsd-license.php New BSD License
825 * @version Release: @package_version@
826 * @link http://pear.php.net/manual/en/core.pear.pear-error.php
827 * @see PEAR::raiseError(), PEAR::throwError()
828 * @since Class available since PHP 4.0.2
832 var $error_message_prefix = '';
833 var $mode = PEAR_ERROR_RETURN;
834 var $level = E_USER_NOTICE;
838 var $backtrace = null;
841 * Only here for backwards compatibility.
843 * Class "Cache_Error" still uses it, among others.
845 * @param string $message Message
846 * @param int $code Error code
847 * @param int $mode Error mode
848 * @param mixed $options See __construct()
849 * @param string $userinfo Additional user/debug info
851 public function PEAR_Error(
852 $message = 'unknown error', $code = null, $mode = null,
853 $options = null, $userinfo = null
856 self::__construct($message, $code, $mode, $options, $userinfo);
860 * PEAR_Error constructor
862 * @param string $message message
864 * @param int $code (optional) error code
866 * @param int $mode (optional) error mode, one of: PEAR_ERROR_RETURN,
867 * PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER,
868 * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION
870 * @param mixed $options (optional) error level, _OR_ in the case of
871 * PEAR_ERROR_CALLBACK, the callback function or object/method
874 * @param string $userinfo (optional) additional user/debug info
879 function __construct($message = 'unknown error', $code = null,
880 $mode = null, $options = null, $userinfo = null)
882 if ($mode === null) {
883 $mode = PEAR_ERROR_RETURN;
885 $this->message = $message;
888 $this->userinfo = $userinfo;
890 $skiptrace = PEAR::getStaticProperty('PEAR_Error', 'skiptrace');
893 $this->backtrace = debug_backtrace();
894 if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) {
895 unset($this->backtrace[0]['object']);
899 if ($mode & PEAR_ERROR_CALLBACK) {
900 $this->level = E_USER_NOTICE;
901 $this->callback = $options;
903 if ($options === null) {
904 $options = E_USER_NOTICE;
907 $this->level = $options;
908 $this->callback = null;
911 if ($this->mode & PEAR_ERROR_PRINT) {
912 if (is_null($options) || is_int($options)) {
918 printf($format, $this->getMessage());
921 if ($this->mode & PEAR_ERROR_TRIGGER) {
922 trigger_error($this->getMessage(), $this->level);
925 if ($this->mode & PEAR_ERROR_DIE) {
926 $msg = $this->getMessage();
927 if (is_null($options) || is_int($options)) {
929 if (substr($msg, -1) != "\n") {
935 printf($format, $msg);
939 if ($this->mode & PEAR_ERROR_CALLBACK && is_callable($this->callback)) {
940 call_user_func($this->callback, $this);
943 if ($this->mode & PEAR_ERROR_EXCEPTION) {
944 trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
945 eval('$e = new Exception($this->message, $this->code);throw($e);');
950 * Get the error message from an error object.
952 * @return string full error message
955 function getMessage()
957 return ($this->error_message_prefix . $this->message);
961 * Get the error mode from an error object.
963 * @return int error mode
972 * Get the callback function/method from an error object.
974 * @return mixed callback function or object/method array
977 function getCallback()
979 return $this->callback;
983 * Get error code from an error object
985 * @return int error code
994 * Get the name of this error/exception.
996 * @return string error/exception name (type)
1001 return get_class($this);
1005 * Get additional debug information supplied by the application.
1007 * @return string debug information
1010 function getDebugInfo()
1012 return $this->getUserInfo();
1016 * Get additional user-supplied information.
1018 * @return string user-supplied information
1021 function getUserInfo()
1023 return $this->userinfo;
1027 * Get the call backtrace from where the error was generated.
1028 * Supported with PHP 4.3.0 or newer.
1030 * @param int $frame (optional) what frame to fetch
1031 * @return array Backtrace, or NULL if not available.
1034 function getBacktrace($frame = null)
1036 if (defined('PEAR_IGNORE_BACKTRACE')) {
1039 if ($frame === null) {
1040 return $this->backtrace;
1042 return $this->backtrace[$frame];
1045 function addUserInfo($info)
1047 if (empty($this->userinfo)) {
1048 $this->userinfo = $info;
1050 $this->userinfo .= " ** $info";
1054 function __toString()
1056 return $this->getMessage();
1060 * Make a string representation of this object.
1062 * @return string a string with an object summary
1068 $levels = array(E_USER_NOTICE => 'notice',
1069 E_USER_WARNING => 'warning',
1070 E_USER_ERROR => 'error');
1071 if ($this->mode & PEAR_ERROR_CALLBACK) {
1072 if (is_array($this->callback)) {
1073 $callback = (is_object($this->callback[0]) ?
1074 strtolower(get_class($this->callback[0])) :
1075 $this->callback[0]) . '::' .
1078 $callback = $this->callback;
1080 return sprintf('[%s: message="%s" code=%d mode=callback ' .
1081 'callback=%s prefix="%s" info="%s"]',
1082 strtolower(get_class($this)), $this->message, $this->code,
1083 $callback, $this->error_message_prefix,
1086 if ($this->mode & PEAR_ERROR_PRINT) {
1089 if ($this->mode & PEAR_ERROR_TRIGGER) {
1090 $modes[] = 'trigger';
1092 if ($this->mode & PEAR_ERROR_DIE) {
1095 if ($this->mode & PEAR_ERROR_RETURN) {
1096 $modes[] = 'return';
1098 return sprintf('[%s: message="%s" code=%d mode=%s level=%s ' .
1099 'prefix="%s" info="%s"]',
1100 strtolower(get_class($this)), $this->message, $this->code,
1101 implode("|", $modes), $levels[$this->level],
1102 $this->error_message_prefix,