3 * PEAR, the PHP Extension and Application Repository
5 * PEAR class and PEAR_Error class
9 * LICENSE: This source file is subject to version 3.0 of the PHP license
10 * that is available through the world-wide-web at the following URI:
11 * http://www.php.net/license/3_0.txt. If you did not receive a copy of
12 * the PHP License and are unable to obtain it through the web, please
13 * send a note to license@php.net so we can mail you a copy immediately.
17 * @author Sterling Hughes <sterling@php.net>
18 * @author Stig Bakken <ssb@php.net>
19 * @author Tomas V.V.Cox <cox@idecnet.com>
20 * @author Greg Beaver <cellog@php.net>
21 * @copyright 1997-2006 The PHP Group
22 * @license http://www.php.net/license/3_0.txt PHP License 3.0
23 * @version CVS: Id: PEAR.php,v 1.97 2006/01/06 04:47:36 cellog Exp
24 * @link http://pear.php.net/package/PEAR
25 * @since File available since Release 0.1
29 * $NetBSD: PEAR.php,v 1.1 2009/10/29 08:29:03 seb Exp $
31 * This is http://cvs.php.net/viewvc.cgi/pear-core/PEAR.php?view=co&pathrev=PEAR_1_4
33 * See $bootstrap_files definition in go-pear.php
40 define('PEAR_ERROR_RETURN', 1);
41 define('PEAR_ERROR_PRINT', 2);
42 define('PEAR_ERROR_TRIGGER', 4);
43 define('PEAR_ERROR_DIE', 8);
44 define('PEAR_ERROR_CALLBACK', 16);
49 define('PEAR_ERROR_EXCEPTION', 32);
51 define('PEAR_ZE2', (function_exists('version_compare') &&
52 version_compare(zend_version(), "2-dev", "ge")));
54 if (substr(PHP_OS
, 0, 3) == 'WIN') {
55 define('OS_WINDOWS', true);
56 define('OS_UNIX', false);
57 define('PEAR_OS', 'Windows');
59 define('OS_WINDOWS', false);
60 define('OS_UNIX', true);
61 define('PEAR_OS', 'Unix'); // blatant assumption
64 // instant backwards compatibility
65 if (!defined('PATH_SEPARATOR')) {
67 define('PATH_SEPARATOR', ';');
69 define('PATH_SEPARATOR', ':');
73 $GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_RETURN
;
74 $GLOBALS['_PEAR_default_error_options'] = E_USER_NOTICE
;
75 $GLOBALS['_PEAR_destructor_object_list'] = array();
76 $GLOBALS['_PEAR_shutdown_funcs'] = array();
77 $GLOBALS['_PEAR_error_handler_stack'] = array();
79 @ini_set
('track_errors', true);
82 * Base class for other PEAR classes. Provides rudimentary
83 * emulation of destructors.
85 * If you want a destructor in your class, inherit PEAR and make a
86 * destructor method called _yourclassname (same name as the
87 * constructor, but with a "_" prefix). Also, in your constructor you
88 * have to call the PEAR constructor: $this->PEAR();.
89 * The destructor method will be called without parameters. Note that
90 * at in some SAPI implementations (such as Apache), any output during
91 * the request shutdown (in which destructors are called) seems to be
92 * discarded. If you need to get any debug information from your
93 * destructor, use error_log(), syslog() or something similar.
95 * IMPORTANT! To use the emulated destructors you need to create the
96 * objects by reference: $obj =& new PEAR_child;
100 * @author Stig Bakken <ssb@php.net>
101 * @author Tomas V.V. Cox <cox@idecnet.com>
102 * @author Greg Beaver <cellog@php.net>
103 * @copyright 1997-2006 The PHP Group
104 * @license http://www.php.net/license/3_0.txt PHP License 3.0
105 * @version Release: @package_version@
106 * @link http://pear.php.net/package/PEAR
108 * @since Class available since PHP 4.0.2
109 * @link http://pear.php.net/manual/en/core.pear.php#core.pear.pear
116 * Whether to enable internal debug messages.
124 * Default error mode for this object.
129 var $_default_error_mode = null;
132 * Default error options used for this object when error mode
133 * is PEAR_ERROR_TRIGGER.
138 var $_default_error_options = null;
141 * Default error handler (callback) for this object, if error mode is
142 * PEAR_ERROR_CALLBACK.
147 var $_default_error_handler = '';
150 * Which class to use for error objects.
155 var $_error_class = 'PEAR_Error';
158 * An array of expected errors.
163 var $_expected_errors = array();
170 * Constructor. Registers this object in
171 * $_PEAR_destructor_object_list for destructor emulation if a
172 * destructor object exists.
174 * @param string $error_class (optional) which class to use for
175 * error objects, defaults to PEAR_Error.
179 function PEAR($error_class = null)
181 $classname = strtolower(get_class($this));
183 print "PEAR constructor called, class=$classname\n";
185 if ($error_class !== null) {
186 $this->_error_class
= $error_class;
188 while ($classname && strcasecmp($classname, "pear")) {
189 $destructor = "_$classname";
190 if (method_exists($this, $destructor)) {
191 global $_PEAR_destructor_object_list;
192 $_PEAR_destructor_object_list[] = &$this;
193 if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
194 register_shutdown_function("_PEAR_call_destructors");
195 $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
199 $classname = get_parent_class($classname);
208 * Destructor (the emulated type of...). Does nothing right now,
209 * but is included for forward compatibility, so subclass
210 * destructors should always call it.
212 * See the note in the class desciption about output from
220 printf("PEAR destructor called, class=%s\n", strtolower(get_class($this)));
225 // {{{ getStaticProperty()
228 * If you have a class that's mostly/entirely static, and you need static
229 * properties, you can use this method to simulate them. Eg. in your method(s)
230 * do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar');
231 * You MUST use a reference, or they will not persist!
234 * @param string $class The calling classname, to prevent clashes
235 * @param string $var The variable to retrieve.
236 * @return mixed A reference to the variable. If not set it will be
237 * auto initialised to NULL.
239 function &getStaticProperty($class, $var)
242 return $properties[$class][$var];
246 // {{{ registerShutdownFunc()
249 * Use this function to register a shutdown method for static
253 * @param mixed $func The function name (or array of class/method) to call
254 * @param mixed $args The arguments to pass to the function
257 function registerShutdownFunc($func, $args = array())
259 // if we are called statically, there is a potential
260 // that no shutdown func is registered. Bug #6445
261 if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
262 register_shutdown_function("_PEAR_call_destructors");
263 $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
265 $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
272 * Tell whether a value is a PEAR error.
274 * @param mixed $data the value to test
275 * @param int $code if $data is an error object, return true
276 * only if $code is a string and
277 * $obj->getMessage() == $code or
278 * $code is an integer and $obj->getCode() == $code
280 * @return bool true if parameter is an error
282 function isError($data, $code = null)
284 if (is_a($data, 'PEAR_Error')) {
285 if (is_null($code)) {
287 } elseif (is_string($code)) {
288 return $data->getMessage() == $code;
290 return $data->getCode() == $code;
297 // {{{ setErrorHandling()
300 * Sets how errors generated by this object should be handled.
301 * Can be invoked both in objects and statically. If called
302 * statically, setErrorHandling sets the default behaviour for all
303 * PEAR objects. If called in an object, setErrorHandling sets
304 * the default behaviour for that object.
307 * One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
308 * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
309 * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION.
311 * @param mixed $options
312 * When $mode is PEAR_ERROR_TRIGGER, this is the error level (one
313 * of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
315 * When $mode is PEAR_ERROR_CALLBACK, this parameter is expected
316 * to be the callback function or method. A callback
317 * function is a string with the name of the function, a
318 * callback method is an array of two elements: the element
319 * at index 0 is the object, and the element at index 1 is
320 * the name of the method to call in the object.
322 * When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is
323 * a printf format string used when printing the error
328 * @see PEAR_ERROR_RETURN
329 * @see PEAR_ERROR_PRINT
330 * @see PEAR_ERROR_TRIGGER
331 * @see PEAR_ERROR_DIE
332 * @see PEAR_ERROR_CALLBACK
333 * @see PEAR_ERROR_EXCEPTION
338 function setErrorHandling($mode = null, $options = null)
340 if (isset($this) && is_a($this, 'PEAR')) {
341 $setmode = &$this->_default_error_mode
;
342 $setoptions = &$this->_default_error_options
;
344 $setmode = &$GLOBALS['_PEAR_default_error_mode'];
345 $setoptions = &$GLOBALS['_PEAR_default_error_options'];
349 case PEAR_ERROR_EXCEPTION
:
350 case PEAR_ERROR_RETURN
:
351 case PEAR_ERROR_PRINT
:
352 case PEAR_ERROR_TRIGGER
:
356 $setoptions = $options;
359 case PEAR_ERROR_CALLBACK
:
361 // class/object method callback
362 if (is_callable($options)) {
363 $setoptions = $options;
365 trigger_error("invalid error callback", E_USER_WARNING
);
370 trigger_error("invalid error mode", E_USER_WARNING
);
379 * This method is used to tell which errors you expect to get.
380 * Expected errors are always returned with error mode
381 * PEAR_ERROR_RETURN. Expected error codes are stored in a stack,
382 * and this method pushes a new element onto it. The list of
383 * expected errors are in effect until they are popped off the
384 * stack with the popExpect() method.
386 * Note that this method can not be called statically
388 * @param mixed $code a single error code or an array of error codes to expect
390 * @return int the new depth of the "expected errors" stack
393 function expectError($code = '*')
395 if (is_array($code)) {
396 array_push($this->_expected_errors
, $code);
398 array_push($this->_expected_errors
, array($code));
400 return sizeof($this->_expected_errors
);
407 * This method pops one element off the expected error codes
410 * @return array the list of error codes that were popped
414 return array_pop($this->_expected_errors
);
418 // {{{ _checkDelExpect()
421 * This method checks unsets an error code if available
423 * @param mixed error code
424 * @return bool true if the error code was unset, false otherwise
428 function _checkDelExpect($error_code)
432 foreach ($this->_expected_errors
AS $key => $error_array) {
433 if (in_array($error_code, $error_array)) {
434 unset($this->_expected_errors
[$key][array_search($error_code, $error_array)]);
438 // clean up empty arrays
439 if (0 == count($this->_expected_errors
[$key])) {
440 unset($this->_expected_errors
[$key]);
450 * This method deletes all occurences of the specified element from
451 * the expected error codes stack.
453 * @param mixed $error_code error code that should be deleted
454 * @return mixed list of error codes that were deleted or error
458 function delExpect($error_code)
462 if ((is_array($error_code) && (0 != count($error_code)))) {
463 // $error_code is a non-empty array here;
464 // we walk through it trying to unset all
466 foreach($error_code as $key => $error) {
467 if ($this->_checkDelExpect($error)) {
473 return $deleted ?
true : PEAR
::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
474 } elseif (!empty($error_code)) {
475 // $error_code comes alone, trying to unset it
476 if ($this->_checkDelExpect($error_code)) {
479 return PEAR
::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
482 // $error_code is empty
483 return PEAR
::raiseError("The expected error you submitted is empty"); // IMPROVE ME
491 * This method is a wrapper that returns an instance of the
492 * configured error class with this object's default error
493 * handling applied. If the $mode and $options parameters are not
494 * specified, the object's defaults are used.
496 * @param mixed $message a text error message or a PEAR error object
498 * @param int $code a numeric error code (it is up to your class
499 * to define these if you want to use codes)
501 * @param int $mode One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
502 * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
503 * PEAR_ERROR_CALLBACK, PEAR_ERROR_EXCEPTION.
505 * @param mixed $options If $mode is PEAR_ERROR_TRIGGER, this parameter
506 * specifies the PHP-internal error level (one of
507 * E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
508 * If $mode is PEAR_ERROR_CALLBACK, this
509 * parameter specifies the callback function or
510 * method. In other error modes this parameter
513 * @param string $userinfo If you need to pass along for example debug
514 * information, this parameter is meant for that.
516 * @param string $error_class The returned error object will be
517 * instantiated from this class, if specified.
519 * @param bool $skipmsg If true, raiseError will only pass error codes,
520 * the error message parameter will be dropped.
523 * @return object a PEAR error object
524 * @see PEAR::setErrorHandling
527 function &raiseError($message = null,
535 // The error is yet a PEAR error object
536 if (is_object($message)) {
537 $code = $message->getCode();
538 $userinfo = $message->getUserInfo();
539 $error_class = $message->getType();
540 $message->error_message_prefix
= '';
541 $message = $message->getMessage();
544 if (isset($this) && isset($this->_expected_errors
) && sizeof($this->_expected_errors
) > 0 && sizeof($exp = end($this->_expected_errors
))) {
545 if ($exp[0] == "*" ||
546 (is_int(reset($exp)) && in_array($code, $exp)) ||
547 (is_string(reset($exp)) && in_array($message, $exp))) {
548 $mode = PEAR_ERROR_RETURN
;
551 // No mode given, try global ones
552 if ($mode === null) {
553 // Class error handler
554 if (isset($this) && isset($this->_default_error_mode
)) {
555 $mode = $this->_default_error_mode
;
556 $options = $this->_default_error_options
;
557 // Global error handler
558 } elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
559 $mode = $GLOBALS['_PEAR_default_error_mode'];
560 $options = $GLOBALS['_PEAR_default_error_options'];
564 if ($error_class !== null) {
566 } elseif (isset($this) && isset($this->_error_class
)) {
567 $ec = $this->_error_class
;
572 $a = new $ec($code, $mode, $options, $userinfo);
575 $a = new $ec($message, $code, $mode, $options, $userinfo);
584 * Simpler form of raiseError with fewer options. In most cases
585 * message, code and userinfo are enough.
587 * @param string $message
590 function &throwError($message = null,
594 if (isset($this) && is_a($this, 'PEAR')) {
595 $a = &$this->raiseError($message, $code, null, null, $userinfo);
598 $a = &PEAR
::raiseError($message, $code, null, null, $userinfo);
604 function staticPushErrorHandling($mode, $options = null)
606 $stack = &$GLOBALS['_PEAR_error_handler_stack'];
607 $def_mode = &$GLOBALS['_PEAR_default_error_mode'];
608 $def_options = &$GLOBALS['_PEAR_default_error_options'];
609 $stack[] = array($def_mode, $def_options);
611 case PEAR_ERROR_EXCEPTION
:
612 case PEAR_ERROR_RETURN
:
613 case PEAR_ERROR_PRINT
:
614 case PEAR_ERROR_TRIGGER
:
618 $def_options = $options;
621 case PEAR_ERROR_CALLBACK
:
623 // class/object method callback
624 if (is_callable($options)) {
625 $def_options = $options;
627 trigger_error("invalid error callback", E_USER_WARNING
);
632 trigger_error("invalid error mode", E_USER_WARNING
);
635 $stack[] = array($mode, $options);
639 function staticPopErrorHandling()
641 $stack = &$GLOBALS['_PEAR_error_handler_stack'];
642 $setmode = &$GLOBALS['_PEAR_default_error_mode'];
643 $setoptions = &$GLOBALS['_PEAR_default_error_options'];
645 list($mode, $options) = $stack[sizeof($stack) - 1];
648 case PEAR_ERROR_EXCEPTION
:
649 case PEAR_ERROR_RETURN
:
650 case PEAR_ERROR_PRINT
:
651 case PEAR_ERROR_TRIGGER
:
655 $setoptions = $options;
658 case PEAR_ERROR_CALLBACK
:
660 // class/object method callback
661 if (is_callable($options)) {
662 $setoptions = $options;
664 trigger_error("invalid error callback", E_USER_WARNING
);
669 trigger_error("invalid error mode", E_USER_WARNING
);
675 // {{{ pushErrorHandling()
678 * Push a new error handler on top of the error handler options stack. With this
679 * you can easily override the actual error handler for some code and restore
680 * it later with popErrorHandling.
682 * @param mixed $mode (same as setErrorHandling)
683 * @param mixed $options (same as setErrorHandling)
685 * @return bool Always true
687 * @see PEAR::setErrorHandling
689 function pushErrorHandling($mode, $options = null)
691 $stack = &$GLOBALS['_PEAR_error_handler_stack'];
692 if (isset($this) && is_a($this, 'PEAR')) {
693 $def_mode = &$this->_default_error_mode
;
694 $def_options = &$this->_default_error_options
;
696 $def_mode = &$GLOBALS['_PEAR_default_error_mode'];
697 $def_options = &$GLOBALS['_PEAR_default_error_options'];
699 $stack[] = array($def_mode, $def_options);
701 if (isset($this) && is_a($this, 'PEAR')) {
702 $this->setErrorHandling($mode, $options);
704 PEAR
::setErrorHandling($mode, $options);
706 $stack[] = array($mode, $options);
711 // {{{ popErrorHandling()
714 * Pop the last error handler used
716 * @return bool Always true
718 * @see PEAR::pushErrorHandling
720 function popErrorHandling()
722 $stack = &$GLOBALS['_PEAR_error_handler_stack'];
724 list($mode, $options) = $stack[sizeof($stack) - 1];
726 if (isset($this) && is_a($this, 'PEAR')) {
727 $this->setErrorHandling($mode, $options);
729 PEAR
::setErrorHandling($mode, $options);
735 // {{{ loadExtension()
738 * OS independant PHP extension load. Remember to take care
739 * on the correct extension name for case sensitive OSes.
741 * @param string $ext The extension name
742 * @return bool Success or not on the dl() call
744 function loadExtension($ext)
746 if (!extension_loaded($ext)) {
747 // if either returns true dl() will produce a FATAL error, stop that
748 if ((ini_get('enable_dl') != 1) ||
(ini_get('safe_mode') == 1)) {
753 } elseif (PHP_OS
== 'HP-UX') {
755 } elseif (PHP_OS
== 'AIX') {
757 } elseif (PHP_OS
== 'OSX') {
762 return @dl
('php_'.$ext.$suffix) || @dl
($ext.$suffix);
770 // {{{ _PEAR_call_destructors()
772 function _PEAR_call_destructors()
774 global $_PEAR_destructor_object_list;
775 if (is_array($_PEAR_destructor_object_list) &&
776 sizeof($_PEAR_destructor_object_list))
778 reset($_PEAR_destructor_object_list);
779 if (@PEAR
::getStaticProperty('PEAR', 'destructlifo')) {
780 $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
782 while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
783 $classname = get_class($objref);
785 $destructor = "_$classname";
786 if (method_exists($objref, $destructor)) {
787 $objref->$destructor();
790 $classname = get_parent_class($classname);
794 // Empty the object list to ensure that destructors are
795 // not called more than once.
796 $_PEAR_destructor_object_list = array();
799 // Now call the shutdown functions
800 if (is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) {
801 foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
802 call_user_func_array($value[0], $value[1]);
809 * Standard PEAR error class for PHP 4
811 * This class is supserseded by {@link PEAR_Exception} in PHP 5
815 * @author Stig Bakken <ssb@php.net>
816 * @author Tomas V.V. Cox <cox@idecnet.com>
817 * @author Gregory Beaver <cellog@php.net>
818 * @copyright 1997-2006 The PHP Group
819 * @license http://www.php.net/license/3_0.txt PHP License 3.0
820 * @version Release: @package_version@
821 * @link http://pear.php.net/manual/en/core.pear.pear-error.php
822 * @see PEAR::raiseError(), PEAR::throwError()
823 * @since Class available since PHP 4.0.2
829 var $error_message_prefix = '';
830 var $mode = PEAR_ERROR_RETURN
;
831 var $level = E_USER_NOTICE
;
835 var $backtrace = null;
841 * PEAR_Error constructor
843 * @param string $message message
845 * @param int $code (optional) error code
847 * @param int $mode (optional) error mode, one of: PEAR_ERROR_RETURN,
848 * PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER,
849 * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION
851 * @param mixed $options (optional) error level, _OR_ in the case of
852 * PEAR_ERROR_CALLBACK, the callback function or object/method
855 * @param string $userinfo (optional) additional user/debug info
860 function PEAR_Error($message = 'unknown error', $code = null,
861 $mode = null, $options = null, $userinfo = null)
863 if ($mode === null) {
864 $mode = PEAR_ERROR_RETURN
;
866 $this->message
= $message;
869 $this->userinfo
= $userinfo;
870 if (function_exists("debug_backtrace")) {
871 if (@!PEAR
::getStaticProperty('PEAR_Error', 'skiptrace')) {
872 $this->backtrace
= debug_backtrace();
875 if ($mode & PEAR_ERROR_CALLBACK
) {
876 $this->level
= E_USER_NOTICE
;
877 $this->callback
= $options;
879 if ($options === null) {
880 $options = E_USER_NOTICE
;
882 $this->level
= $options;
883 $this->callback
= null;
885 if ($this->mode
& PEAR_ERROR_PRINT
) {
886 if (is_null($options) ||
is_int($options)) {
891 printf($format, $this->getMessage());
893 if ($this->mode
& PEAR_ERROR_TRIGGER
) {
894 trigger_error($this->getMessage(), $this->level
);
896 if ($this->mode
& PEAR_ERROR_DIE
) {
897 $msg = $this->getMessage();
898 if (is_null($options) ||
is_int($options)) {
900 if (substr($msg, -1) != "\n") {
906 die(sprintf($format, $msg));
908 if ($this->mode
& PEAR_ERROR_CALLBACK
) {
909 if (is_callable($this->callback
)) {
910 call_user_func($this->callback
, $this);
913 if ($this->mode
& PEAR_ERROR_EXCEPTION
) {
914 trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING
);
915 eval('$e = new Exception($this->message, $this->code);throw($e);');
923 * Get the error mode from an error object.
925 * @return int error mode
936 * Get the callback function/method from an error object.
938 * @return mixed callback function or object/method array
941 function getCallback() {
942 return $this->callback
;
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
);
965 * Get error code from an error object
967 * @return int error code
979 * Get the name of this error/exception.
981 * @return string error/exception name (type)
986 return get_class($this);
993 * Get additional user-supplied information.
995 * @return string user-supplied information
998 function getUserInfo()
1000 return $this->userinfo
;
1004 // {{{ getDebugInfo()
1007 * Get additional debug information supplied by the application.
1009 * @return string debug information
1012 function getDebugInfo()
1014 return $this->getUserInfo();
1018 // {{{ getBacktrace()
1021 * Get the call backtrace from where the error was generated.
1022 * Supported with PHP 4.3.0 or newer.
1024 * @param int $frame (optional) what frame to fetch
1025 * @return array Backtrace, or NULL if not available.
1028 function getBacktrace($frame = null)
1030 if (defined('PEAR_IGNORE_BACKTRACE')) {
1033 if ($frame === null) {
1034 return $this->backtrace
;
1036 return $this->backtrace
[$frame];
1040 // {{{ addUserInfo()
1042 function addUserInfo($info)
1044 if (empty($this->userinfo
)) {
1045 $this->userinfo
= $info;
1047 $this->userinfo
.= " ** $info";
1055 * Make a string representation of this object.
1057 * @return string a string with an object summary
1060 function toString() {
1062 $levels = array(E_USER_NOTICE
=> 'notice',
1063 E_USER_WARNING
=> 'warning',
1064 E_USER_ERROR
=> 'error');
1065 if ($this->mode
& PEAR_ERROR_CALLBACK
) {
1066 if (is_array($this->callback
)) {
1067 $callback = (is_object($this->callback
[0]) ?
1068 strtolower(get_class($this->callback
[0])) :
1069 $this->callback
[0]) . '::' .
1072 $callback = $this->callback
;
1074 return sprintf('[%s: message="%s" code=%d mode=callback '.
1075 'callback=%s prefix="%s" info="%s"]',
1076 strtolower(get_class($this)), $this->message
, $this->code
,
1077 $callback, $this->error_message_prefix
,
1080 if ($this->mode
& PEAR_ERROR_PRINT
) {
1083 if ($this->mode
& PEAR_ERROR_TRIGGER
) {
1084 $modes[] = 'trigger';
1086 if ($this->mode
& PEAR_ERROR_DIE
) {
1089 if ($this->mode
& PEAR_ERROR_RETURN
) {
1090 $modes[] = 'return';
1092 return sprintf('[%s: message="%s" code=%d mode=%s level=%s '.
1093 'prefix="%s" info="%s"]',
1094 strtolower(get_class($this)), $this->message
, $this->code
,
1095 implode("|", $modes), $levels[$this->level
],
1096 $this->error_message_prefix
,