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;
70 @ini_set(
'track_errors',
true);
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)));
234 if (!isset($properties[$class])) {
235 $properties[$class] =
array();
237 if (!array_key_exists($var, $properties[$class])) {
238 $properties[$class][$var] = null;
240 return $properties[$class][$var];
259 if (!isset(
$GLOBALS[
'_PEAR_SHUTDOWN_REGISTERED'])) {
260 register_shutdown_function(
"_PEAR_call_destructors");
261 $GLOBALS[
'_PEAR_SHUTDOWN_REGISTERED'] =
true;
282 if (is_a(
$data,
'PEAR_Error')) {
283 if (is_null(
$code)) {
285 } elseif (is_string(
$code)) {
339 $setmode = &
$GLOBALS[
'_PEAR_default_error_mode'];
340 $setoptions = &
$GLOBALS[
'_PEAR_default_error_options'];
360 trigger_error(
"invalid error callback", E_USER_WARNING);
365 trigger_error(
"invalid error mode", E_USER_WARNING);
390 if (is_array(
$code)) {
391 array_push($this->_expected_errors,
$code);
393 array_push($this->_expected_errors,
array(
$code));
409 return array_pop($this->_expected_errors);
427 foreach ($this->_expected_errors AS $key => $error_array) {
428 if (in_array($error_code, $error_array)) {
429 unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
434 if (0 == count($this->_expected_errors[$key])) {
435 unset($this->_expected_errors[$key]);
457 if ((is_array($error_code) && (0 != count($error_code)))) {
461 foreach($error_code as $key =>
$error) {
468 return $deleted ? true :
PEAR::raiseError(
"The expected error you submitted does not exist");
469 } elseif (!empty($error_code)) {
531 if (is_object($message)) {
532 $code = $message->getCode();
533 $userinfo = $message->getUserInfo();
534 $error_class = $message->getType();
535 $message->error_message_prefix =
'';
536 $message = $message->getMessage();
539 if (isset($this) && isset($this->_expected_errors) &&
sizeof($this->_expected_errors) > 0 &&
sizeof($exp = end($this->_expected_errors))) {
540 if ($exp[0] ==
"*" ||
541 (is_int(reset($exp)) && in_array(
$code, $exp)) ||
542 (is_string(reset($exp)) && in_array($message, $exp))) {
547 if ($mode === null) {
549 if (isset($this) && isset($this->_default_error_mode)) {
553 } elseif (isset(
$GLOBALS[
'_PEAR_default_error_mode'])) {
554 $mode =
$GLOBALS[
'_PEAR_default_error_mode'];
559 if ($error_class !== null) {
561 } elseif (isset($this) && isset($this->_error_class)) {
566 if (intval(PHP_VERSION) < 5) {
599 if (isset($this) && is_a($this,
'PEAR')) {
611 $stack = &
$GLOBALS[
'_PEAR_error_handler_stack'];
612 $def_mode = &
$GLOBALS[
'_PEAR_default_error_mode'];
613 $def_options = &
$GLOBALS[
'_PEAR_default_error_options'];
614 $stack[] =
array($def_mode, $def_options);
632 trigger_error(
"invalid error callback", E_USER_WARNING);
637 trigger_error(
"invalid error mode", E_USER_WARNING);
646 $stack = &
$GLOBALS[
'_PEAR_error_handler_stack'];
647 $setmode = &
$GLOBALS[
'_PEAR_default_error_mode'];
648 $setoptions = &
$GLOBALS[
'_PEAR_default_error_options'];
650 list($mode,
$options) = $stack[
sizeof($stack) - 1];
669 trigger_error(
"invalid error callback", E_USER_WARNING);
674 trigger_error(
"invalid error mode", E_USER_WARNING);
696 $stack = &
$GLOBALS[
'_PEAR_error_handler_stack'];
697 if (isset($this) && is_a($this,
'PEAR')) {
701 $def_mode = &
$GLOBALS[
'_PEAR_default_error_mode'];
702 $def_options = &
$GLOBALS[
'_PEAR_default_error_options'];
704 $stack[] =
array($def_mode, $def_options);
706 if (isset($this) && is_a($this,
'PEAR')) {
727 $stack = &
$GLOBALS[
'_PEAR_error_handler_stack'];
729 list($mode,
$options) = $stack[
sizeof($stack) - 1];
731 if (isset($this) && is_a($this,
'PEAR')) {
751 if (!extension_loaded($ext)) {
753 if ((ini_get(
'enable_dl') != 1) || (ini_get(
'safe_mode') == 1)) {
758 } elseif (PHP_OS ==
'HP-UX') {
760 } elseif (PHP_OS ==
'AIX') {
762 } elseif (PHP_OS ==
'OSX') {
767 return @dl(
'php_'.$ext.$suffix) || @dl($ext.$suffix);
779 global $_PEAR_destructor_object_list;
780 if (is_array($_PEAR_destructor_object_list) &&
781 sizeof($_PEAR_destructor_object_list))
783 reset($_PEAR_destructor_object_list);
785 $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
787 while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
788 $classname = get_class($objref);
790 $destructor =
"_$classname";
791 if (method_exists($objref, $destructor)) {
792 $objref->$destructor();
795 $classname = get_parent_class($classname);
801 $_PEAR_destructor_object_list =
array();
805 if (is_array(
$GLOBALS[
'_PEAR_shutdown_funcs']) AND !empty(
$GLOBALS[
'_PEAR_shutdown_funcs'])) {
806 foreach (
$GLOBALS[
'_PEAR_shutdown_funcs'] as $value) {
807 call_user_func_array($value[0], $value[1]);
834 var $error_message_prefix =
'';
836 var $level = E_USER_NOTICE;
840 var $backtrace = null;
865 public function __construct($message =
'unknown error', $code = null,
866 $mode = null,
$options = null, $userinfo = null)
868 if ($mode === null) {
871 $this->message = $message;
874 $this->userinfo = $userinfo;
876 $this->backtrace = debug_backtrace();
877 if (isset($this->backtrace[0]) && isset($this->backtrace[0][
'object'])) {
878 unset($this->backtrace[0][
'object']);
882 $this->level = E_USER_NOTICE;
889 $this->callback = null;
897 printf($format, $this->getMessage());
900 trigger_error($this->getMessage(), $this->level);
903 $msg = $this->getMessage();
906 if (substr($msg, -1) !=
"\n") {
912 die(sprintf($format, $msg));
914 if ($this->mode & PEAR_ERROR_CALLBACK) {
915 if (is_callable($this->callback)) {
916 call_user_func($this->callback, $this);
920 trigger_error(
"PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
921 $e =
new Exception($this->message, $this->code);
throw($e);
948 return $this->callback;
963 return ($this->error_message_prefix . $this->message);
992 return get_class($this);
1006 return $this->userinfo;
1020 return $this->getUserInfo();
1036 if (
defined(
'PEAR_IGNORE_BACKTRACE')) {
1039 if ($frame === null) {
1040 return $this->backtrace;
1042 return $this->backtrace[$frame];
1050 if (empty($this->userinfo)) {
1051 $this->userinfo =
$info;
1053 $this->userinfo .=
" ** $info";
1061 return $this->getMessage();
1074 $levels =
array(E_USER_NOTICE =>
'notice',
1075 E_USER_WARNING =>
'warning',
1076 E_USER_ERROR =>
'error');
1078 if (is_array($this->callback)) {
1079 $callback = (is_object($this->callback[0]) ?
1080 strtolower(get_class($this->callback[0])) :
1081 $this->callback[0]) .
'::' .
1084 $callback = $this->callback;
1086 return sprintf(
'[%s: message="%s" code=%d mode=callback '.
1087 'callback=%s prefix="%s" info="%s"]',
1088 strtolower(get_class($this)), $this->message, $this->code,
1089 $callback, $this->error_message_prefix,
1096 $modes[] =
'trigger';
1102 $modes[] =
'return';
1104 return sprintf(
'[%s: message="%s" code=%d mode=%s level=%s '.
1105 'prefix="%s" info="%s"]',
1106 strtolower(get_class($this)), $this->message, $this->code,
1107 implode(
"|", $modes), $levels[$this->level],
1108 $this->error_message_prefix,
registerShutdownFunc($func, $args=array())
Use this function to register a shutdown method for static classes.
static & getStaticProperty($class, $var)
If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them.
loadExtension($ext)
OS independant PHP extension load.
const PEAR_ERROR_CALLBACK
getMode()
Get the error mode from an error object.
_checkDelExpect($error_code)
This method checks unsets an error code if available.
static setErrorHandling($mode=null, $options=null)
Sets how errors generated by this object should be handled.
getMessage()
Get the error message from an error object.
__construct($message='unknown error', $code=null, $mode=null, $options=null, $userinfo=null)
PEAR_Error constructor.
getBacktrace($frame=null)
Get the call backtrace from where the error was generated.
getCallback()
Get the callback function/method from an error object.
getUserInfo()
Get additional user-supplied information.
& throwError($message=null, $code=null, $userinfo=null)
Simpler form of raiseError with fewer options.
getCode()
Get error code from an error object.
const PEAR_ERROR_EXCEPTION
WARNING: obsolete.
if(!is_array($argv)) $options
popErrorHandling()
Pop the last error handler used.
getDebugInfo()
Get additional debug information supplied by the application.
popExpect()
This method pops one element off the expected error codes stack.
const PEAR_ERROR_RETURN
#+ ERROR constants
getType()
Get the name of this error/exception.
expectError($code=' *')
This method is used to tell which errors you expect to get.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
delExpect($error_code)
This method deletes all occurences of the specified element from the expected error codes stack...
pushErrorHandling($mode, $options=null)
Push a new error handler on top of the error handler options stack.
_PEAR()
Destructor (the emulated type of...).
Create styles array
The data for the language used.
toString()
Make a string representation of this object.
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object's de...
__construct($error_class=null)
Constructor.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
staticPushErrorHandling($mode, $options=null)
isError($data, $code=null)
Tell whether a value is a PEAR error.