24define(
'PEAR_ERROR_RETURN', 1);
25define(
'PEAR_ERROR_PRINT', 2);
26define(
'PEAR_ERROR_TRIGGER', 4);
27define(
'PEAR_ERROR_DIE', 8);
28define(
'PEAR_ERROR_CALLBACK', 16);
33define(
'PEAR_ERROR_EXCEPTION', 32);
36if (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');
47$GLOBALS[
'_PEAR_default_error_options'] = E_USER_NOTICE;
48$GLOBALS[
'_PEAR_destructor_object_list'] = array();
50$GLOBALS[
'_PEAR_error_handler_stack'] = array();
52if(function_exists(
'ini_set')) {
53 @ini_set(
'track_errors',
true);
143 'setErrorHandling' =>
true,
144 'raiseError' =>
true,
145 'throwError' =>
true,
146 'pushErrorHandling' =>
true,
147 'popErrorHandling' =>
true,
162 $classname = strtolower(get_class($this));
164 print
"PEAR constructor called, class=$classname\n";
167 if ($error_class !==
null) {
168 $this->_error_class = $error_class;
171 while ($classname && strcasecmp($classname,
"pear")) {
172 $destructor =
"_$classname";
173 if (method_exists($this, $destructor)) {
174 global $_PEAR_destructor_object_list;
175 $_PEAR_destructor_object_list[] = $this;
176 if (!isset(
$GLOBALS[
'_PEAR_SHUTDOWN_REGISTERED'])) {
177 register_shutdown_function(
"_PEAR_call_destructors");
178 $GLOBALS[
'_PEAR_SHUTDOWN_REGISTERED'] =
true;
182 $classname = get_parent_class($classname);
194 public function PEAR($error_class =
null)
196 self::__construct($error_class);
212 printf(
"PEAR destructor called, class=%s\n", strtolower(get_class($this)));
216 public function __call($method, $arguments)
218 if (!isset(self::$bivalentMethods[$method])) {
219 if (PHP_VERSION_ID < 70000) {
221 'Call to undefined method PEAR::' . $method .
'()',
E_USER_ERROR
224 throw new Error(
'Call to undefined method PEAR::' . $method .
'()');
227 return call_user_func_array(
228 array(__CLASS__,
'_' . $method),
229 array_merge(array($this), $arguments)
235 if (!isset(self::$bivalentMethods[$method])) {
236 if (PHP_VERSION_ID < 70000) {
238 'Call to undefined method PEAR::' . $method .
'()',
E_USER_ERROR
241 throw new Error(
'Call to undefined method PEAR::' . $method .
'()');
244 return call_user_func_array(
245 array(__CLASS__,
'_' . $method),
246 array_merge(array(
null), $arguments)
264 if (!isset($properties[$class])) {
265 $properties[$class] = array();
268 if (!array_key_exists($var, $properties[$class])) {
269 $properties[$class][$var] =
null;
272 return $properties[$class][$var];
288 if (!isset(
$GLOBALS[
'_PEAR_SHUTDOWN_REGISTERED'])) {
289 register_shutdown_function(
"_PEAR_call_destructors");
290 $GLOBALS[
'_PEAR_SHUTDOWN_REGISTERED'] =
true;
292 $GLOBALS[
'_PEAR_shutdown_funcs'][] = array($func, $args);
306 public static function isError($data, $code =
null)
308 if (!is_a($data,
'PEAR_Error')) {
312 if (is_null($code)) {
314 } elseif (is_string($code)) {
315 return $data->getMessage() == $code;
318 return $data->getCode() == $code;
363 $object, $mode =
null,
$options =
null
365 if ($object !==
null) {
366 $setmode = &$object->_default_error_mode;
367 $setoptions = &$object->_default_error_options;
369 $setmode = &
$GLOBALS[
'_PEAR_default_error_mode'];
370 $setoptions = &
$GLOBALS[
'_PEAR_default_error_options'];
390 trigger_error(
"invalid error callback", E_USER_WARNING);
395 trigger_error(
"invalid error mode", E_USER_WARNING);
417 if (is_array($code)) {
418 array_push($this->_expected_errors, $code);
420 array_push($this->_expected_errors, array($code));
422 return count($this->_expected_errors);
433 return array_pop($this->_expected_errors);
447 foreach ($this->_expected_errors as $key => $error_array) {
448 if (in_array($error_code, $error_array)) {
449 unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
454 if (0 == count($this->_expected_errors[$key])) {
455 unset($this->_expected_errors[$key]);
474 if ((is_array($error_code) && (0 != count($error_code)))) {
477 foreach ($error_code as $key => $error) {
481 return $deleted ? true : PEAR::raiseError(
"The expected error you submitted does not exist");
482 } elseif (!empty($error_code)) {
488 return PEAR::raiseError(
"The expected error you submitted does not exist");
492 return PEAR::raiseError(
"The expected error you submitted is empty");
541 if (is_object($message)) {
542 $code = $message->getCode();
543 $userinfo = $message->getUserInfo();
544 $error_class = $message->getType();
545 $message->error_message_prefix =
'';
546 $message = $message->getMessage();
551 isset($object->_expected_errors) &&
552 count($object->_expected_errors) > 0 &&
553 count($exp = end($object->_expected_errors))
555 if ($exp[0] ===
"*" ||
556 (is_int(reset($exp)) && in_array($code, $exp)) ||
557 (is_string(reset($exp)) && in_array($message, $exp))
564 if ($mode ===
null) {
566 if ($object !==
null && isset($object->_default_error_mode)) {
567 $mode = $object->_default_error_mode;
568 $options = $object->_default_error_options;
570 } elseif (isset(
$GLOBALS[
'_PEAR_default_error_mode'])) {
571 $mode =
$GLOBALS[
'_PEAR_default_error_mode'];
576 if ($error_class !==
null) {
578 } elseif ($object !==
null && isset($object->_error_class)) {
579 $ec = $object->_error_class;
585 $a =
new $ec($code, $mode,
$options, $userinfo);
587 $a =
new $ec($message, $code, $mode,
$options, $userinfo);
608 protected static function _throwError($object, $message =
null, $code =
null, $userinfo =
null)
610 if ($object !==
null) {
611 $a = $object->raiseError($message, $code,
null,
null, $userinfo);
615 $a = PEAR::raiseError($message, $code,
null,
null, $userinfo);
622 $def_mode = &
$GLOBALS[
'_PEAR_default_error_mode'];
623 $def_options = &
$GLOBALS[
'_PEAR_default_error_options'];
624 $stack[] = array($def_mode, $def_options);
642 trigger_error(
"invalid error callback", E_USER_WARNING);
647 trigger_error(
"invalid error mode", E_USER_WARNING);
657 $setmode = &
$GLOBALS[
'_PEAR_default_error_mode'];
658 $setoptions = &
$GLOBALS[
'_PEAR_default_error_options'];
679 trigger_error(
"invalid error callback", E_USER_WARNING);
684 trigger_error(
"invalid error mode", E_USER_WARNING);
705 if ($object !==
null) {
706 $def_mode = &$object->_default_error_mode;
707 $def_options = &$object->_default_error_options;
709 $def_mode = &
$GLOBALS[
'_PEAR_default_error_mode'];
710 $def_options = &
$GLOBALS[
'_PEAR_default_error_options'];
712 $stack[] = array($def_mode, $def_options);
714 if ($object !==
null) {
715 $object->setErrorHandling($mode,
$options);
717 PEAR::setErrorHandling($mode,
$options);
736 if ($object !==
null) {
737 $object->setErrorHandling($mode,
$options);
739 PEAR::setErrorHandling($mode,
$options);
753 if (extension_loaded($ext)) {
759 function_exists(
'dl') ===
false ||
760 ini_get(
'enable_dl') != 1
767 } elseif (PHP_OS ==
'HP-UX') {
769 } elseif (PHP_OS ==
'AIX') {
771 } elseif (PHP_OS ==
'OSX') {
777 return @dl(
'php_'.$ext.$suffix) || @dl($ext.$suffix);
789 if ($source_date_epoch = getenv(
'SOURCE_DATE_EPOCH')) {
790 if (preg_match(
'/^\d+$/', $source_date_epoch)) {
791 return (
int) $source_date_epoch;
794 self::raiseError(
"Invalid SOURCE_DATE_EPOCH: $source_date_epoch");
805 global $_PEAR_destructor_object_list;
806 if (is_array($_PEAR_destructor_object_list) &&
807 sizeof($_PEAR_destructor_object_list))
809 reset($_PEAR_destructor_object_list);
811 $destructLifoExists = PEAR::getStaticProperty(
'PEAR',
'destructlifo');
813 if ($destructLifoExists) {
814 $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
817 foreach ($_PEAR_destructor_object_list as $k => $objref) {
818 $classname = get_class($objref);
820 $destructor =
"_$classname";
821 if (method_exists($objref, $destructor)) {
822 $objref->$destructor();
825 $classname = get_parent_class($classname);
831 $_PEAR_destructor_object_list = array();
836 isset(
$GLOBALS[
'_PEAR_shutdown_funcs']) &&
837 is_array(
$GLOBALS[
'_PEAR_shutdown_funcs']) &&
838 !empty(
$GLOBALS[
'_PEAR_shutdown_funcs'])
840 foreach (
$GLOBALS[
'_PEAR_shutdown_funcs'] as $value) {
841 call_user_func_array($value[0], $value[1]);
897 if (
$mode ===
null) {
905 $skiptrace = PEAR::getStaticProperty(
'PEAR_Error',
'skiptrace');
908 $this->backtrace = debug_backtrace();
909 if (isset($this->backtrace[0]) && isset($this->backtrace[0][
'object'])) {
910 unset($this->backtrace[0][
'object']);
915 $this->level = E_USER_NOTICE;
923 $this->callback =
null;
937 trigger_error($this->
getMessage(), $this->level);
944 if (substr($msg, -1) !=
"\n") {
950 printf($format, $msg);
955 call_user_func($this->callback, $this);
959 trigger_error(
"PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
960 eval(
'$e = new Exception($this->message, $this->code);throw($e);');
1012 return ($this->error_message_prefix . $this->message);
1034 return get_class($this);
1069 if (defined(
'PEAR_IGNORE_BACKTRACE')) {
1072 if ($frame ===
null) {
1075 return $this->backtrace[$frame];
1080 if (empty($this->userinfo)) {
1081 $this->userinfo = $info;
1083 $this->userinfo .=
" ** $info";
1101 $levels = array(E_USER_NOTICE =>
'notice',
1102 E_USER_WARNING =>
'warning',
1105 if (is_array($this->callback)) {
1106 $callback = (is_object($this->callback[0]) ?
1107 strtolower(get_class($this->callback[0])) :
1108 $this->callback[0]) .
'::' .
1113 return sprintf(
'[%s: message="%s" code=%d mode=callback '.
1114 'callback=%s prefix="%s" info="%s"]',
1115 strtolower(get_class($this)), $this->message, $this->code,
1123 $modes[] =
'trigger';
1129 $modes[] =
'return';
1131 return sprintf(
'[%s: message="%s" code=%d mode=%s level=%s '.
1132 'prefix="%s" info="%s"]',
1133 strtolower(get_class($this)), $this->message, $this->code,
1134 implode(
"|", $modes), $levels[$this->level],
1135 $this->error_message_prefix,
const PEAR_ERROR_EXCEPTION
const PEAR_ERROR_CALLBACK
$GLOBALS['_PEAR_default_error_mode']
__construct($message='unknown error', $code=null, $mode=null, $options=null, $userinfo=null)
getBacktrace($frame=null)
PEAR_Error( $message='unknown error', $code=null, $mode=null, $options=null, $userinfo=null)
static & getStaticProperty($class, $var)
static _popErrorHandling($object)
static __callStatic($method, $arguments)
static staticPopErrorHandling()
static loadExtension($ext)
__construct($error_class=null)
static _setErrorHandling( $object, $mode=null, $options=null)
static getSourceDateEpoch()
static staticPushErrorHandling($mode, $options=null)
static _pushErrorHandling($object, $mode, $options=null)
static registerShutdownFunc($func, $args=array())
__call($method, $arguments)
static _throwError($object, $message=null, $code=null, $userinfo=null)
_checkDelExpect($error_code)
static _raiseError($object, $message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
static isError($data, $code=null)
if(!extension_loaded('winbinder')) if(!dl('php_winbinder.dll')) trigger_error("WinBinder extension could not be loaded.\n" E_USER_ERROR