31 define(
'PEAR_ERROR_RETURN', 1);
32 define(
'PEAR_ERROR_PRINT', 2);
33 define(
'PEAR_ERROR_TRIGGER', 4);
34 define(
'PEAR_ERROR_DIE', 8);
35 define(
'PEAR_ERROR_CALLBACK', 16);
40 define(
'PEAR_ERROR_EXCEPTION', 32);
42 define(
'PEAR_ZE2', (function_exists(
'version_compare') &&
43 version_compare(zend_version(),
"2-dev",
"ge")));
45 if (substr(PHP_OS, 0, 3) ==
'WIN') {
46 define(
'OS_WINDOWS',
true);
47 define(
'OS_UNIX',
false);
48 define(
'PEAR_OS',
'Windows');
50 define(
'OS_WINDOWS',
false);
51 define(
'OS_UNIX',
true);
52 define(
'PEAR_OS',
'Unix');
56 if (!defined(
'PATH_SEPARATOR')) {
58 define(
'PATH_SEPARATOR',
';');
60 define(
'PATH_SEPARATOR',
':');
65 $GLOBALS[
'_PEAR_default_error_options'] = E_USER_NOTICE;
66 $GLOBALS[
'_PEAR_destructor_object_list'] = array();
68 $GLOBALS[
'_PEAR_error_handler_stack'] = array();
70 @ini_set(
'track_errors',
true);
170 function PEAR($error_class = null)
172 $classname = strtolower(get_class($this));
174 print
"PEAR constructor called, class=$classname\n";
176 if ($error_class !== null) {
177 $this->_error_class = $error_class;
179 while ($classname && strcasecmp($classname,
"pear")) {
180 $destructor =
"_$classname";
181 if (method_exists($this, $destructor)) {
182 global $_PEAR_destructor_object_list;
183 $_PEAR_destructor_object_list[] = &$this;
184 if (!isset(
$GLOBALS[
'_PEAR_SHUTDOWN_REGISTERED'])) {
185 register_shutdown_function(
"_PEAR_call_destructors");
186 $GLOBALS[
'_PEAR_SHUTDOWN_REGISTERED'] =
true;
190 $classname = get_parent_class($classname);
211 printf(
"PEAR destructor called, class=%s\n", strtolower(get_class($this)));
233 if (!isset($properties[$class])) {
234 $properties[$class] = array();
236 if (!array_key_exists($var, $properties[$class])) {
237 $properties[$class][$var] = null;
239 return $properties[$class][$var];
258 if (!isset(
$GLOBALS[
'_PEAR_SHUTDOWN_REGISTERED'])) {
259 register_shutdown_function(
"_PEAR_call_destructors");
260 $GLOBALS[
'_PEAR_SHUTDOWN_REGISTERED'] =
true;
262 $GLOBALS[
'_PEAR_shutdown_funcs'][] = array($func, $args);
281 if (is_a(
$data,
'PEAR_Error')) {
282 if (is_null($code)) {
284 } elseif (is_string($code)) {
285 return $data->getMessage() == $code;
287 return $data->getCode() == $code;
337 if (isset($this) && is_a($this,
'PEAR')) {
341 $setmode = &
$GLOBALS[
'_PEAR_default_error_mode'];
342 $setoptions = &
$GLOBALS[
'_PEAR_default_error_options'];
353 $setoptions = $options;
359 if (is_callable($options)) {
360 $setoptions = $options;
362 trigger_error(
"invalid error callback", E_USER_WARNING);
367 trigger_error(
"invalid error mode", E_USER_WARNING);
392 if (is_array($code)) {
393 array_push($this->_expected_errors, $code);
395 array_push($this->_expected_errors, array($code));
411 return array_pop($this->_expected_errors);
429 foreach ($this->_expected_errors AS $key => $error_array) {
430 if (in_array($error_code, $error_array)) {
431 unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
436 if (0 == count($this->_expected_errors[$key])) {
437 unset($this->_expected_errors[$key]);
459 if ((is_array($error_code) && (0 != count($error_code)))) {
463 foreach($error_code as $key =>
$error) {
470 return $deleted ?
true :
PEAR::raiseError(
"The expected error you submitted does not exist");
471 } elseif (!empty($error_code)) {
533 if (is_object($message)) {
534 $code = $message->getCode();
535 $userinfo = $message->getUserInfo();
536 $error_class = $message->getType();
537 $message->error_message_prefix =
'';
538 $message = $message->getMessage();
541 if (isset($this) && isset($this->_expected_errors) &&
sizeof($this->_expected_errors) > 0 &&
sizeof($exp = end($this->_expected_errors))) {
542 if ($exp[0] ==
"*" ||
543 (is_int(reset($exp)) && in_array($code, $exp)) ||
544 (is_string(reset($exp)) && in_array($message, $exp))) {
549 if ($mode === null) {
551 if (isset($this) && isset($this->_default_error_mode)) {
555 } elseif (isset(
$GLOBALS[
'_PEAR_default_error_mode'])) {
556 $mode =
$GLOBALS[
'_PEAR_default_error_mode'];
557 $options =
$GLOBALS[
'_PEAR_default_error_options'];
561 if ($error_class !== null) {
563 } elseif (isset($this) && isset($this->_error_class)) {
568 if (intval(PHP_VERSION) < 5) {
570 include
'PEAR/FixPHP5PEARWarnings.php';
574 $a =
new $ec($code, $mode, $options, $userinfo);
576 $a =
new $ec($message, $code, $mode, $options, $userinfo);
595 if (isset($this) && is_a($this,
'PEAR')) {
596 $a = &$this->
raiseError($message, $code, null, null, $userinfo);
607 $stack = &
$GLOBALS[
'_PEAR_error_handler_stack'];
608 $def_mode = &
$GLOBALS[
'_PEAR_default_error_mode'];
609 $def_options = &
$GLOBALS[
'_PEAR_default_error_options'];
610 $stack[] = array($def_mode, $def_options);
619 $def_options = $options;
625 if (is_callable($options)) {
626 $def_options = $options;
628 trigger_error(
"invalid error callback", E_USER_WARNING);
633 trigger_error(
"invalid error mode", E_USER_WARNING);
636 $stack[] = array($mode, $options);
642 $stack = &
$GLOBALS[
'_PEAR_error_handler_stack'];
643 $setmode = &
$GLOBALS[
'_PEAR_default_error_mode'];
644 $setoptions = &
$GLOBALS[
'_PEAR_default_error_options'];
646 list($mode, $options) = $stack[
sizeof($stack) - 1];
656 $setoptions = $options;
662 if (is_callable($options)) {
663 $setoptions = $options;
665 trigger_error(
"invalid error callback", E_USER_WARNING);
670 trigger_error(
"invalid error mode", E_USER_WARNING);
692 $stack = &
$GLOBALS[
'_PEAR_error_handler_stack'];
693 if (isset($this) && is_a($this,
'PEAR')) {
697 $def_mode = &
$GLOBALS[
'_PEAR_default_error_mode'];
698 $def_options = &
$GLOBALS[
'_PEAR_default_error_options'];
700 $stack[] = array($def_mode, $def_options);
702 if (isset($this) && is_a($this,
'PEAR')) {
707 $stack[] = array($mode, $options);
723 $stack = &
$GLOBALS[
'_PEAR_error_handler_stack'];
725 list($mode, $options) = $stack[
sizeof($stack) - 1];
727 if (isset($this) && is_a($this,
'PEAR')) {
747 if (!extension_loaded($ext)) {
749 if ((ini_get(
'enable_dl') != 1) || (ini_get(
'safe_mode') == 1)) {
754 } elseif (PHP_OS ==
'HP-UX') {
756 } elseif (PHP_OS ==
'AIX') {
758 } elseif (PHP_OS ==
'OSX') {
763 return @dl(
'php_'.$ext.$suffix) || @dl($ext.$suffix);
775 global $_PEAR_destructor_object_list;
776 if (is_array($_PEAR_destructor_object_list) &&
777 sizeof($_PEAR_destructor_object_list))
779 reset($_PEAR_destructor_object_list);
781 $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
783 while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
784 $classname = get_class($objref);
786 $destructor =
"_$classname";
787 if (method_exists($objref, $destructor)) {
788 $objref->$destructor();
791 $classname = get_parent_class($classname);
797 $_PEAR_destructor_object_list = array();
801 if (is_array(
$GLOBALS[
'_PEAR_shutdown_funcs']) AND !empty(
$GLOBALS[
'_PEAR_shutdown_funcs'])) {
802 foreach (
$GLOBALS[
'_PEAR_shutdown_funcs'] as $value) {
803 call_user_func_array($value[0], $value[1]);
864 if (
$mode === null) {
872 $this->backtrace = debug_backtrace();
873 if (isset($this->backtrace[0]) && isset($this->backtrace[0][
'object'])) {
874 unset($this->backtrace[0][
'object']);
878 $this->level = E_USER_NOTICE;
879 $this->callback = $options;
881 if ($options === null) {
882 $options = E_USER_NOTICE;
884 $this->level = $options;
885 $this->callback = null;
888 if (is_null($options) || is_int($options)) {
896 trigger_error($this->
getMessage(), $this->level);
900 if (is_null($options) || is_int($options)) {
902 if (substr($msg, -1) !=
"\n") {
908 die(sprintf($format, $msg));
910 if ($this->mode & PEAR_ERROR_CALLBACK) {
911 if (is_callable($this->callback)) {
912 call_user_func($this->callback, $this);
916 trigger_error(
"PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
917 eval(
'$e = new Exception($this->message, $this->code);throw($e);');
944 return $this->callback;
959 return ($this->error_message_prefix . $this->message);
988 return get_class($this);
1032 if (defined(
'PEAR_IGNORE_BACKTRACE')) {
1035 if ($frame === null) {
1038 return $this->backtrace[$frame];
1046 if (empty($this->userinfo)) {
1047 $this->userinfo = $info;
1049 $this->userinfo .=
" ** $info";
1070 $levels = array(E_USER_NOTICE =>
'notice',
1071 E_USER_WARNING =>
'warning',
1072 E_USER_ERROR =>
'error');
1074 if (is_array($this->callback)) {
1075 $callback = (is_object($this->callback[0]) ?
1076 strtolower(get_class($this->callback[0])) :
1077 $this->callback[0]) .
'::' .
1080 $callback = $this->callback;
1082 return sprintf(
'[%s: message="%s" code=%d mode=callback '.
1083 'callback=%s prefix="%s" info="%s"]',
1084 strtolower(get_class($this)), $this->message, $this->code,
1085 $callback, $this->error_message_prefix,
1092 $modes[] =
'trigger';
1098 $modes[] =
'return';
1100 return sprintf(
'[%s: message="%s" code=%d mode=%s level=%s '.
1101 'prefix="%s" info="%s"]',
1102 strtolower(get_class($this)), $this->message, $this->code,
1103 implode(
"|", $modes), $levels[$this->level],
1104 $this->error_message_prefix,