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 * @version CVS: $Id: PEAR.php 313023 2011-07-06 19:17:11Z dufuz $
18 * @link http://pear.php.net/package/PEAR
19 * @since File available since Release 0.1
25 define('PEAR_ERROR_RETURN', 1);
26 define('PEAR_ERROR_PRINT', 2);
27 define('PEAR_ERROR_TRIGGER', 4);
28 define('PEAR_ERROR_DIE', 8);
29 define('PEAR_ERROR_CALLBACK', 16);
34 define('PEAR_ERROR_EXCEPTION', 32);
36 define('PEAR_ZE2', (function_exists('version_compare') &&
37 version_compare(zend_version(), "2-dev", "ge")));
39 if (substr(PHP_OS, 0, 3) == 'WIN') {
40 define('OS_WINDOWS', true);
41 define('OS_UNIX', false);
42 define('PEAR_OS', 'Windows');
44 define('OS_WINDOWS', false);
45 define('OS_UNIX', true);
46 define('PEAR_OS', 'Unix'); // blatant assumption
49 $GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_RETURN;
50 $GLOBALS['_PEAR_default_error_options'] = E_USER_NOTICE;
51 $GLOBALS['_PEAR_destructor_object_list'] = array();
52 $GLOBALS['_PEAR_shutdown_funcs'] = array();
53 $GLOBALS['_PEAR_error_handler_stack'] = array();
55 @ini_set('track_errors', true);
58 * Base class for other PEAR classes. Provides rudimentary
59 * emulation of destructors.
61 * If you want a destructor in your class, inherit PEAR and make a
62 * destructor method called _yourclassname (same name as the
63 * constructor, but with a "_" prefix). Also, in your constructor you
64 * have to call the PEAR constructor: $this->PEAR();.
65 * The destructor method will be called without parameters. Note that
66 * at in some SAPI implementations (such as Apache), any output during
67 * the request shutdown (in which destructors are called) seems to be
68 * discarded. If you need to get any debug information from your
69 * destructor, use error_log(), syslog() or something similar.
71 * IMPORTANT! To use the emulated destructors you need to create the
72 * objects by reference: $obj =& new PEAR_child;
76 * @author Stig Bakken <ssb@php.net>
77 * @author Tomas V.V. Cox <cox@idecnet.com>
78 * @author Greg Beaver <cellog@php.net>
79 * @copyright 1997-2006 The PHP Group
80 * @license http://opensource.org/licenses/bsd-license.php New BSD License
81 * @version Release: 1.9.4
82 * @link http://pear.php.net/package/PEAR
84 * @since Class available since PHP 4.0.2
85 * @link http://pear.php.net/manual/en/core.pear.php#core.pear.pear
90 * Whether to enable internal debug messages.
98 * Default error mode for this object.
103 var $_default_error_mode = null;
106 * Default error options used for this object when error mode
107 * is PEAR_ERROR_TRIGGER.
112 var $_default_error_options = null;
115 * Default error handler (callback) for this object, if error mode is
116 * PEAR_ERROR_CALLBACK.
121 var $_default_error_handler = '';
124 * Which class to use for error objects.
129 var $_error_class = 'PEAR_Error';
132 * An array of expected errors.
137 var $_expected_errors = array();
140 * Constructor. Registers this object in
141 * $_PEAR_destructor_object_list for destructor emulation if a
142 * destructor object exists.
144 * @param string $error_class (optional) which class to use for
145 * error objects, defaults to PEAR_Error.
149 function PEAR($error_class = null)
151 $classname = strtolower(get_class($this));
153 print "PEAR constructor called, class=$classname\n";
156 if ($error_class !== null) {
157 $this->_error_class = $error_class;
160 while ($classname && strcasecmp($classname, "pear")) {
161 $destructor = "_$classname";
162 if (method_exists($this, $destructor)) {
163 global $_PEAR_destructor_object_list;
164 $_PEAR_destructor_object_list[] = &$this;
165 if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
166 register_shutdown_function("_PEAR_call_destructors");
167 $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
171 $classname = get_parent_class($classname);
177 * Destructor (the emulated type of...). Does nothing right now,
178 * but is included for forward compatibility, so subclass
179 * destructors should always call it.
181 * See the note in the class desciption about output from
189 printf("PEAR destructor called, class=%s\n", strtolower(get_class($this)));
194 * If you have a class that's mostly/entirely static, and you need static
195 * properties, you can use this method to simulate them. Eg. in your method(s)
196 * do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar');
197 * You MUST use a reference, or they will not persist!
200 * @param string $class The calling classname, to prevent clashes
201 * @param string $var The variable to retrieve.
202 * @return mixed A reference to the variable. If not set it will be
203 * auto initialised to NULL.
205 static function &getStaticProperty($class, $var)
208 if (!isset($properties[$class])) {
209 $properties[$class] = array();
212 if (!array_key_exists($var, $properties[$class])) {
213 $properties[$class][$var] = null;
219 return $properties[$class][$var];
223 * Use this function to register a shutdown method for static
227 * @param mixed $func The function name (or array of class/method) to call
228 * @param mixed $args The arguments to pass to the function
231 function registerShutdownFunc($func, $args = array())
233 // if we are called statically, there is a potential
234 // that no shutdown func is registered. Bug #6445
235 if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
236 register_shutdown_function("_PEAR_call_destructors");
237 $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
239 $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
243 * Tell whether a value is a PEAR error.
245 * @param mixed $data the value to test
246 * @param int $code if $data is an error object, return true
247 * only if $code is a string and
248 * $obj->getMessage() == $code or
249 * $code is an integer and $obj->getCode() == $code
251 * @return bool true if parameter is an error
253 static function isError($data, $code = null)
255 if (!is_a($data, 'PEAR_Error')) {
259 if (is_null($code)) {
261 } elseif (is_string($code)) {
262 return $data->getMessage() == $code;
265 return $data->getCode() == $code;
269 * Sets how errors generated by this object should be handled.
270 * Can be invoked both in objects and statically. If called
271 * statically, setErrorHandling sets the default behaviour for all
272 * PEAR objects. If called in an object, setErrorHandling sets
273 * the default behaviour for that object.
276 * One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
277 * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
278 * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION.
280 * @param mixed $options
281 * When $mode is PEAR_ERROR_TRIGGER, this is the error level (one
282 * of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
284 * When $mode is PEAR_ERROR_CALLBACK, this parameter is expected
285 * to be the callback function or method. A callback
286 * function is a string with the name of the function, a
287 * callback method is an array of two elements: the element
288 * at index 0 is the object, and the element at index 1 is
289 * the name of the method to call in the object.
291 * When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is
292 * a printf format string used when printing the error
297 * @see PEAR_ERROR_RETURN
298 * @see PEAR_ERROR_PRINT
299 * @see PEAR_ERROR_TRIGGER
300 * @see PEAR_ERROR_DIE
301 * @see PEAR_ERROR_CALLBACK
302 * @see PEAR_ERROR_EXCEPTION
306 static function setErrorHandling($mode = null, $options = null)
308 //if (isset($this) && is_a($this, 'PEAR')) {
309 // $setmode = &$this->_default_error_mode;
310 // $setoptions = &$this->_default_error_options;
312 $setmode = &$GLOBALS['_PEAR_default_error_mode'];
313 $setoptions = &$GLOBALS['_PEAR_default_error_options'];
317 case PEAR_ERROR_EXCEPTION:
318 case PEAR_ERROR_RETURN:
319 case PEAR_ERROR_PRINT:
320 case PEAR_ERROR_TRIGGER:
324 $setoptions = $options;
327 case PEAR_ERROR_CALLBACK:
329 // class/object method callback
330 if (is_callable($options)) {
331 $setoptions = $options;
333 trigger_error("invalid error callback", E_USER_WARNING);
338 trigger_error("invalid error mode", E_USER_WARNING);
344 * This method is used to tell which errors you expect to get.
345 * Expected errors are always returned with error mode
346 * PEAR_ERROR_RETURN. Expected error codes are stored in a stack,
347 * and this method pushes a new element onto it. The list of
348 * expected errors are in effect until they are popped off the
349 * stack with the popExpect() method.
351 * Note that this method can not be called statically
353 * @param mixed $code a single error code or an array of error codes to expect
355 * @return int the new depth of the "expected errors" stack
358 function expectError($code = '*')
360 if (is_array($code)) {
361 array_push($this->_expected_errors, $code);
363 array_push($this->_expected_errors, array($code));
365 return count($this->_expected_errors);
369 * This method pops one element off the expected error codes
372 * @return array the list of error codes that were popped
376 return array_pop($this->_expected_errors);
380 * This method checks unsets an error code if available
382 * @param mixed error code
383 * @return bool true if the error code was unset, false otherwise
387 function _checkDelExpect($error_code)
390 foreach ($this->_expected_errors as $key => $error_array) {
391 if (in_array($error_code, $error_array)) {
392 unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
396 // clean up empty arrays
397 if (0 == count($this->_expected_errors[$key])) {
398 unset($this->_expected_errors[$key]);
406 * This method deletes all occurences of the specified element from
407 * the expected error codes stack.
409 * @param mixed $error_code error code that should be deleted
410 * @return mixed list of error codes that were deleted or error
414 function delExpect($error_code)
417 if ((is_array($error_code) && (0 != count($error_code)))) {
418 // $error_code is a non-empty array here; we walk through it trying
419 // to unset all values
420 foreach ($error_code as $key => $error) {
421 $deleted = $this->_checkDelExpect($error) ? true : false;
424 return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
425 } elseif (!empty($error_code)) {
426 // $error_code comes alone, trying to unset it
427 if ($this->_checkDelExpect($error_code)) {
431 return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
434 // $error_code is empty
435 return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
439 * This method is a wrapper that returns an instance of the
440 * configured error class with this object's default error
441 * handling applied. If the $mode and $options parameters are not
442 * specified, the object's defaults are used.
444 * @param mixed $message a text error message or a PEAR error object
446 * @param int $code a numeric error code (it is up to your class
447 * to define these if you want to use codes)
449 * @param int $mode One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
450 * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
451 * PEAR_ERROR_CALLBACK, PEAR_ERROR_EXCEPTION.
453 * @param mixed $options If $mode is PEAR_ERROR_TRIGGER, this parameter
454 * specifies the PHP-internal error level (one of
455 * E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
456 * If $mode is PEAR_ERROR_CALLBACK, this
457 * parameter specifies the callback function or
458 * method. In other error modes this parameter
461 * @param string $userinfo If you need to pass along for example debug
462 * information, this parameter is meant for that.
464 * @param string $error_class The returned error object will be
465 * instantiated from this class, if specified.
467 * @param bool $skipmsg If true, raiseError will only pass error codes,
468 * the error message parameter will be dropped.
471 * @return object a PEAR error object
472 * @see PEAR::setErrorHandling
475 function &raiseError($message = null,
483 // The error is yet a PEAR error object
484 if (is_object($message)) {
485 $code = $message->getCode();
486 $userinfo = $message->getUserInfo();
487 $error_class = $message->getType();
488 $message->error_message_prefix = '';
489 $message = $message->getMessage();
494 isset($this->_expected_errors) &&
495 count($this->_expected_errors) > 0 &&
496 count($exp = end($this->_expected_errors))
498 if ($exp[0] == "*" ||
499 (is_int(reset($exp)) && in_array($code, $exp)) ||
500 (is_string(reset($exp)) && in_array($message, $exp))
502 $mode = PEAR_ERROR_RETURN;
506 // No mode given, try global ones
507 if ($mode === null) {
508 // Class error handler
509 if (isset($this) && isset($this->_default_error_mode)) {
510 $mode = $this->_default_error_mode;
511 $options = $this->_default_error_options;
512 // Global error handler
513 } elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
514 $mode = $GLOBALS['_PEAR_default_error_mode'];
515 $options = $GLOBALS['_PEAR_default_error_options'];
519 if ($error_class !== null) {
521 } elseif (isset($this) && isset($this->_error_class)) {
522 $ec = $this->_error_class;
527 if (intval(PHP_VERSION) < 5) {
528 // little non-eval hack to fix bug #12147
529 include 'PEAR/FixPHP5PEARWarnings.php';
534 $a = new $ec($code, $mode, $options, $userinfo);
536 $a = new $ec($message, $code, $mode, $options, $userinfo);
542 static function staticRaiseError ($message = null,
550 return $p->raiseError($message ,$code , $mode , $options , $userinfo , $error_class , $skipmsg );
554 * Simpler form of raiseError with fewer options. In most cases
555 * message, code and userinfo are enough.
557 * @param mixed $message a text error message or a PEAR error object
559 * @param int $code a numeric error code (it is up to your class
560 * to define these if you want to use codes)
562 * @param string $userinfo If you need to pass along for example debug
563 * information, this parameter is meant for that.
566 * @return object a PEAR error object
567 * @see PEAR::raiseError
569 function &throwError($message = null, $code = null, $userinfo = null)
571 if (isset($this) && is_a($this, 'PEAR')) {
572 $a = &$this->raiseError($message, $code, null, null, $userinfo);
576 $a = &PEAR::raiseError($message, $code, null, null, $userinfo);
580 function staticPushErrorHandling($mode, $options = null)
582 $stack = &$GLOBALS['_PEAR_error_handler_stack'];
583 $def_mode = &$GLOBALS['_PEAR_default_error_mode'];
584 $def_options = &$GLOBALS['_PEAR_default_error_options'];
585 $stack[] = array($def_mode, $def_options);
587 case PEAR_ERROR_EXCEPTION:
588 case PEAR_ERROR_RETURN:
589 case PEAR_ERROR_PRINT:
590 case PEAR_ERROR_TRIGGER:
594 $def_options = $options;
597 case PEAR_ERROR_CALLBACK:
599 // class/object method callback
600 if (is_callable($options)) {
601 $def_options = $options;
603 trigger_error("invalid error callback", E_USER_WARNING);
608 trigger_error("invalid error mode", E_USER_WARNING);
611 $stack[] = array($mode, $options);
615 function staticPopErrorHandling()
617 $stack = &$GLOBALS['_PEAR_error_handler_stack'];
618 $setmode = &$GLOBALS['_PEAR_default_error_mode'];
619 $setoptions = &$GLOBALS['_PEAR_default_error_options'];
621 list($mode, $options) = $stack[sizeof($stack) - 1];
624 case PEAR_ERROR_EXCEPTION:
625 case PEAR_ERROR_RETURN:
626 case PEAR_ERROR_PRINT:
627 case PEAR_ERROR_TRIGGER:
631 $setoptions = $options;
634 case PEAR_ERROR_CALLBACK:
636 // class/object method callback
637 if (is_callable($options)) {
638 $setoptions = $options;
640 trigger_error("invalid error callback", E_USER_WARNING);
645 trigger_error("invalid error mode", E_USER_WARNING);
652 * Push a new error handler on top of the error handler options stack. With this
653 * you can easily override the actual error handler for some code and restore
654 * it later with popErrorHandling.
656 * @param mixed $mode (same as setErrorHandling)
657 * @param mixed $options (same as setErrorHandling)
659 * @return bool Always true
661 * @see PEAR::setErrorHandling
663 function pushErrorHandling($mode, $options = null)
665 $stack = &$GLOBALS['_PEAR_error_handler_stack'];
666 if (isset($this) && is_a($this, 'PEAR')) {
667 $def_mode = &$this->_default_error_mode;
668 $def_options = &$this->_default_error_options;
670 $def_mode = &$GLOBALS['_PEAR_default_error_mode'];
671 $def_options = &$GLOBALS['_PEAR_default_error_options'];
673 $stack[] = array($def_mode, $def_options);
675 if (isset($this) && is_a($this, 'PEAR')) {
676 $this->setErrorHandling($mode, $options);
678 PEAR::setErrorHandling($mode, $options);
680 $stack[] = array($mode, $options);
685 * Pop the last error handler used
687 * @return bool Always true
689 * @see PEAR::pushErrorHandling
691 function popErrorHandling()
693 $stack = &$GLOBALS['_PEAR_error_handler_stack'];
695 list($mode, $options) = $stack[sizeof($stack) - 1];
697 if (isset($this) && is_a($this, 'PEAR')) {
698 $this->setErrorHandling($mode, $options);
700 PEAR::setErrorHandling($mode, $options);
706 * OS independant PHP extension load. Remember to take care
707 * on the correct extension name for case sensitive OSes.
709 * @param string $ext The extension name
710 * @return bool Success or not on the dl() call
712 function loadExtension($ext)
714 if (extension_loaded($ext)) {
718 // if either returns true dl() will produce a FATAL error, stop that
720 function_exists('dl') === false ||
721 ini_get('enable_dl') != 1 ||
722 ini_get('safe_mode') == 1
729 } elseif (PHP_OS == 'HP-UX') {
731 } elseif (PHP_OS == 'AIX') {
733 } elseif (PHP_OS == 'OSX') {
739 return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
744 include_once 'PEAR5.php';
747 function _PEAR_call_destructors()
749 global $_PEAR_destructor_object_list;
750 if (is_array($_PEAR_destructor_object_list) &&
751 sizeof($_PEAR_destructor_object_list))
753 reset($_PEAR_destructor_object_list);
755 $destructLifoExists = PEAR5::getStaticProperty('PEAR', 'destructlifo');
757 $destructLifoExists = PEAR::getStaticProperty('PEAR', 'destructlifo');
760 if ($destructLifoExists) {
761 $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
764 while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
765 $classname = get_class($objref);
767 $destructor = "_$classname";
768 if (method_exists($objref, $destructor)) {
769 $objref->$destructor();
772 $classname = get_parent_class($classname);
776 // Empty the object list to ensure that destructors are
777 // not called more than once.
778 $_PEAR_destructor_object_list = array();
781 // Now call the shutdown functions
783 isset($GLOBALS['_PEAR_shutdown_funcs']) &&
784 is_array($GLOBALS['_PEAR_shutdown_funcs']) &&
785 !empty($GLOBALS['_PEAR_shutdown_funcs'])
787 foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
788 call_user_func_array($value[0], $value[1]);
794 * Standard PEAR error class for PHP 4
796 * This class is supserseded by {@link PEAR_Exception} in PHP 5
800 * @author Stig Bakken <ssb@php.net>
801 * @author Tomas V.V. Cox <cox@idecnet.com>
802 * @author Gregory Beaver <cellog@php.net>
803 * @copyright 1997-2006 The PHP Group
804 * @license http://opensource.org/licenses/bsd-license.php New BSD License
805 * @version Release: 1.9.4
806 * @link http://pear.php.net/manual/en/core.pear.pear-error.php
807 * @see PEAR::raiseError(), PEAR::throwError()
808 * @since Class available since PHP 4.0.2
812 var $error_message_prefix = '';
813 var $mode = PEAR_ERROR_RETURN;
814 var $level = E_USER_NOTICE;
818 var $backtrace = null;
821 * PEAR_Error constructor
823 * @param string $message message
825 * @param int $code (optional) error code
827 * @param int $mode (optional) error mode, one of: PEAR_ERROR_RETURN,
828 * PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER,
829 * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION
831 * @param mixed $options (optional) error level, _OR_ in the case of
832 * PEAR_ERROR_CALLBACK, the callback function or object/method
835 * @param string $userinfo (optional) additional user/debug info
840 function PEAR_Error($message = 'unknown error', $code = null,
841 $mode = null, $options = null, $userinfo = null)
843 if ($mode === null) {
844 $mode = PEAR_ERROR_RETURN;
846 $this->message = $message;
849 $this->userinfo = $userinfo;
852 $skiptrace = PEAR5::getStaticProperty('PEAR_Error', 'skiptrace');
854 $skiptrace = PEAR::getStaticProperty('PEAR_Error', 'skiptrace');
858 $this->backtrace = debug_backtrace();
859 if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) {
860 unset($this->backtrace[0]['object']);
864 if ($mode & PEAR_ERROR_CALLBACK) {
865 $this->level = E_USER_NOTICE;
866 $this->callback = $options;
868 if ($options === null) {
869 $options = E_USER_NOTICE;
872 $this->level = $options;
873 $this->callback = null;
876 if ($this->mode & PEAR_ERROR_PRINT) {
877 if (is_null($options) || is_int($options)) {
883 printf($format, $this->getMessage());
886 if ($this->mode & PEAR_ERROR_TRIGGER) {
887 trigger_error($this->getMessage(), $this->level);
890 if ($this->mode & PEAR_ERROR_DIE) {
891 $msg = $this->getMessage();
892 if (is_null($options) || is_int($options)) {
894 if (substr($msg, -1) != "\n") {
900 die(sprintf($format, $msg));
904 if ($this->mode & PEAR_ERROR_CALLBACK && is_callable($this->callback)) {
905 call_user_func($this->callback, $this);
908 if ($this->mode & PEAR_ERROR_EXCEPTION) {
909 trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
910 eval('$e = new Exception($this->message, $this->code);throw($e);');
915 * Get the error mode from an error object.
917 * @return int error mode
926 * Get the callback function/method from an error object.
928 * @return mixed callback function or object/method array
931 function getCallback()
933 return $this->callback;
937 * Get the error message from an error object.
939 * @return string full error message
942 function getMessage()
944 return ($this->error_message_prefix . $this->message);
948 * Get error code from an error object
950 * @return int error code
959 * Get the name of this error/exception.
961 * @return string error/exception name (type)
966 return get_class($this);
970 * Get additional user-supplied information.
972 * @return string user-supplied information
975 function getUserInfo()
977 return $this->userinfo;
981 * Get additional debug information supplied by the application.
983 * @return string debug information
986 function getDebugInfo()
988 return $this->getUserInfo();
992 * Get the call backtrace from where the error was generated.
993 * Supported with PHP 4.3.0 or newer.
995 * @param int $frame (optional) what frame to fetch
996 * @return array Backtrace, or NULL if not available.
999 function getBacktrace($frame = null)
1001 if (defined('PEAR_IGNORE_BACKTRACE')) {
1004 if ($frame === null) {
1005 return $this->backtrace;
1007 return $this->backtrace[$frame];
1010 function addUserInfo($info)
1012 if (empty($this->userinfo)) {
1013 $this->userinfo = $info;
1015 $this->userinfo .= " ** $info";
1019 function __toString()
1021 return $this->getMessage();
1025 * Make a string representation of this object.
1027 * @return string a string with an object summary
1033 $levels = array(E_USER_NOTICE => 'notice',
1034 E_USER_WARNING => 'warning',
1035 E_USER_ERROR => 'error');
1036 if ($this->mode & PEAR_ERROR_CALLBACK) {
1037 if (is_array($this->callback)) {
1038 $callback = (is_object($this->callback[0]) ?
1039 strtolower(get_class($this->callback[0])) :
1040 $this->callback[0]) . '::' .
1043 $callback = $this->callback;
1045 return sprintf('[%s: message="%s" code=%d mode=callback '.
1046 'callback=%s prefix="%s" info="%s"]',
1047 strtolower(get_class($this)), $this->message, $this->code,
1048 $callback, $this->error_message_prefix,
1049 is_string($this->userinfo) ? $this->userinfo : print_r($this->userinfo,true));
1051 if ($this->mode & PEAR_ERROR_PRINT) {
1054 if ($this->mode & PEAR_ERROR_TRIGGER) {
1055 $modes[] = 'trigger';
1057 if ($this->mode & PEAR_ERROR_DIE) {
1060 if ($this->mode & PEAR_ERROR_RETURN) {
1061 $modes[] = 'return';
1063 return sprintf('[%s: message="%s" code=%d mode=%s level=%s '.
1064 'prefix="%s" info="%s"]',
1065 strtolower(get_class($this)), $this->message, $this->code,
1066 implode("|", $modes), $levels[$this->level],
1067 $this->error_message_prefix,