ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PEAR Class Reference
+ Inheritance diagram for PEAR:
+ Collaboration diagram for PEAR:

Public Member Functions

 __construct ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). More...
 
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes. More...
 
 isError ($data, $code=null)
 Tell whether a value is a PEAR error. More...
 
 expectError ($code=' *')
 This method is used to tell which errors you expect to get. More...
 
 popExpect ()
 This method pops one element off the expected error codes stack. More...
 
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available. More...
 
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack. More...
 
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 default error handling applied. More...
 
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options. More...
 
 staticPushErrorHandling ($mode, $options=null)
 
 staticPopErrorHandling ()
 
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack. More...
 
 popErrorHandling ()
 Pop the last error handler used. More...
 
 loadExtension ($ext)
 OS independant PHP extension load. More...
 

Static Public Member Functions

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. More...
 
static setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. More...
 

Data Fields

 $_debug = false
 
 $_default_error_mode = null
 
 $_default_error_options = null
 
 $_default_error_handler = ''
 
 $_error_class = 'PEAR_Error'
 
 $_expected_errors = array()
 

Detailed Description

Definition at line 102 of file PEAR.php.

Constructor & Destructor Documentation

◆ __construct()

PEAR::__construct (   $error_class = null)

Constructor.

Registers this object in $_PEAR_destructor_object_list for destructor emulation if a destructor object exists.

Parameters
string$error_class(optional) which class to use for error objects, defaults to PEAR_Error. @access public
Returns
void

Reimplemented in ilAdvancedMDRecordParser, ilManifestParser, ilSimpleXMLTableDataParser, ilSoapMailXmlParser, ilXMLResultSetParser, ilMDSaxParser, ilMDSaxParser, ilMDSaxParser, ilCopyWizardSettingsXMLParser, and ilAssQuestionSkillAssignmentXmlParser.

Definition at line 170 of file PEAR.php.

171 {
172 $classname = strtolower(get_class($this));
173 if ($this->_debug) {
174 print "PEAR constructor called, class=$classname\n";
175 }
176 if ($error_class !== null) {
177 $this->_error_class = $error_class;
178 }
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;
187 }
188 break;
189 } else {
190 $classname = get_parent_class($classname);
191 }
192 }
193 }
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
if(! $in) print

References $GLOBALS, and print.

Member Function Documentation

◆ _checkDelExpect()

PEAR::_checkDelExpect (   $error_code)

This method checks unsets an error code if available.

Parameters
mixederror code
Returns
bool true if the error code was unset, false otherwise @access private
Since
PHP 4.3.0

Definition at line 423 of file PEAR.php.

424 {
425 $deleted = false;
426
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)]);
430 $deleted = true;
431 }
432
433 // clean up empty arrays
434 if (0 == count($this->_expected_errors[$key])) {
435 unset($this->_expected_errors[$key]);
436 }
437 }
438 return $deleted;
439 }
$key
Definition: croninfo.php:18

References $key.

Referenced by delExpect().

+ Here is the caller graph for this function:

◆ _PEAR()

PEAR::_PEAR ( )

Destructor (the emulated type of...).

Does nothing right now, but is included for forward compatibility, so subclass destructors should always call it.

See the note in the class desciption about output from destructors.

@access public

Returns
void

Definition at line 209 of file PEAR.php.

209 {
210 if ($this->_debug) {
211 printf("PEAR destructor called, class=%s\n", strtolower(get_class($this)));
212 }
213 }

◆ delExpect()

PEAR::delExpect (   $error_code)

This method deletes all occurences of the specified element from the expected error codes stack.

Parameters
mixed$error_codeerror code that should be deleted
Returns
mixed list of error codes that were deleted or error @access public
Since
PHP 4.3.0

Definition at line 453 of file PEAR.php.

454 {
455 $deleted = false;
456
457 if ((is_array($error_code) && (0 != count($error_code)))) {
458 // $error_code is a non-empty array here;
459 // we walk through it trying to unset all
460 // values
461 foreach($error_code as $key => $error) {
462 if ($this->_checkDelExpect($error)) {
463 $deleted = true;
464 } else {
465 $deleted = false;
466 }
467 }
468 return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
469 } elseif (!empty($error_code)) {
470 // $error_code comes alone, trying to unset it
471 if ($this->_checkDelExpect($error_code)) {
472 return true;
473 } else {
474 return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
475 }
476 } else {
477 // $error_code is empty
478 return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
479 }
480 }
_checkDelExpect($error_code)
This method checks unsets an error code if available.
Definition: PEAR.php:423
& 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...
Definition: PEAR.php:522

References $key, _checkDelExpect(), and raiseError().

+ Here is the call graph for this function:

◆ expectError()

PEAR::expectError (   $code = '*')

This method is used to tell which errors you expect to get.

Expected errors are always returned with error mode PEAR_ERROR_RETURN. Expected error codes are stored in a stack, and this method pushes a new element onto it. The list of expected errors are in effect until they are popped off the stack with the popExpect() method.

Note that this method can not be called statically

Parameters
mixed$codea single error code or an array of error codes to expect
Returns
int the new depth of the "expected errors" stack @access public

Definition at line 388 of file PEAR.php.

389 {
390 if (is_array($code)) {
391 array_push($this->_expected_errors, $code);
392 } else {
393 array_push($this->_expected_errors, array($code));
394 }
395 return sizeof($this->_expected_errors);
396 }
$_expected_errors
Definition: PEAR.php:154
$code
Definition: example_050.php:99

References $_expected_errors, and $code.

◆ getStaticProperty()

static & PEAR::getStaticProperty (   $class,
  $var 
)
static

If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them.

Eg. in your method(s) do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar'); You MUST use a reference, or they will not persist!

@access public

Parameters
string$classThe calling classname, to prevent clashes
string$varThe variable to retrieve.
Returns
mixed A reference to the variable. If not set it will be auto initialised to NULL.

Definition at line 231 of file PEAR.php.

232 {
233 static $properties;
234 if (!isset($properties[$class])) {
235 $properties[$class] = array();
236 }
237 if (!array_key_exists($var, $properties[$class])) {
238 $properties[$class][$var] = null;
239 }
240 return $properties[$class][$var];
241 }

Referenced by PEAR_Error\__construct(), and _PEAR_call_destructors().

+ Here is the caller graph for this function:

◆ isError()

PEAR::isError (   $data,
  $code = null 
)

Tell whether a value is a PEAR error.

Parameters
mixed$datathe value to test
int$codeif $data is an error object, return true only if $code is a string and $obj->getMessage() == $code or $code is an integer and $obj->getCode() == $code @access public
Returns
bool true if parameter is an error

Definition at line 280 of file PEAR.php.

281 {
282 if (is_a($data, 'PEAR_Error')) {
283 if (is_null($code)) {
284 return true;
285 } elseif (is_string($code)) {
286 return $data->getMessage() == $code;
287 } else {
288 return $data->getCode() == $code;
289 }
290 }
291 return false;
292 }
$data
Definition: bench.php:6

References $code, and $data.

◆ loadExtension()

PEAR::loadExtension (   $ext)

OS independant PHP extension load.

Remember to take care on the correct extension name for case sensitive OSes.

Parameters
string$extThe extension name
Returns
bool Success or not on the dl() call

Definition at line 749 of file PEAR.php.

750 {
751 if (!extension_loaded($ext)) {
752 // if either returns true dl() will produce a FATAL error, stop that
753 if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) {
754 return false;
755 }
756 if (OS_WINDOWS) {
757 $suffix = '.dll';
758 } elseif (PHP_OS == 'HP-UX') {
759 $suffix = '.sl';
760 } elseif (PHP_OS == 'AIX') {
761 $suffix = '.a';
762 } elseif (PHP_OS == 'OSX') {
763 $suffix = '.bundle';
764 } else {
765 $suffix = '.so';
766 }
767 return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
768 }
769 return true;
770 }

◆ popErrorHandling()

PEAR::popErrorHandling ( )

Pop the last error handler used.

Returns
bool Always true
See also
PEAR::pushErrorHandling

Definition at line 725 of file PEAR.php.

726 {
727 $stack = &$GLOBALS['_PEAR_error_handler_stack'];
728 array_pop($stack);
729 list($mode, $options) = $stack[sizeof($stack) - 1];
730 array_pop($stack);
731 if (isset($this) && is_a($this, 'PEAR')) {
732 $this->setErrorHandling($mode, $options);
733 } else {
735 }
736 return true;
737 }
static setErrorHandling($mode=null, $options=null)
Sets how errors generated by this object should be handled.
Definition: PEAR.php:337

References $GLOBALS, PHPMailer\PHPMailer\$options, and setErrorHandling().

+ Here is the call graph for this function:

◆ popExpect()

PEAR::popExpect ( )

This method pops one element off the expected error codes stack.

Returns
array the list of error codes that were popped

Definition at line 407 of file PEAR.php.

408 {
409 return array_pop($this->_expected_errors);
410 }

◆ pushErrorHandling()

PEAR::pushErrorHandling (   $mode,
  $options = null 
)

Push a new error handler on top of the error handler options stack.

With this you can easily override the actual error handler for some code and restore it later with popErrorHandling.

Parameters
mixed$mode(same as setErrorHandling)
mixed$options(same as setErrorHandling)
Returns
bool Always true
See also
PEAR::setErrorHandling

Definition at line 694 of file PEAR.php.

695 {
696 $stack = &$GLOBALS['_PEAR_error_handler_stack'];
697 if (isset($this) && is_a($this, 'PEAR')) {
698 $def_mode = &$this->_default_error_mode;
699 $def_options = &$this->_default_error_options;
700 } else {
701 $def_mode = &$GLOBALS['_PEAR_default_error_mode'];
702 $def_options = &$GLOBALS['_PEAR_default_error_options'];
703 }
704 $stack[] = array($def_mode, $def_options);
705
706 if (isset($this) && is_a($this, 'PEAR')) {
707 $this->setErrorHandling($mode, $options);
708 } else {
710 }
711 $stack[] = array($mode, $options);
712 return true;
713 }
$_default_error_mode
Definition: PEAR.php:120
$_default_error_options
Definition: PEAR.php:129

References $_default_error_mode, $_default_error_options, $GLOBALS, PHPMailer\PHPMailer\$options, and setErrorHandling().

+ Here is the call graph for this function:

◆ raiseError()

& PEAR::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 default error handling applied.

If the $mode and $options parameters are not specified, the object's defaults are used.

Parameters
mixed$messagea text error message or a PEAR error object
int$codea numeric error code (it is up to your class to define these if you want to use codes)
int$modeOne of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT, PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE, PEAR_ERROR_CALLBACK, PEAR_ERROR_EXCEPTION.
mixed$optionsIf $mode is PEAR_ERROR_TRIGGER, this parameter specifies the PHP-internal error level (one of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR). If $mode is PEAR_ERROR_CALLBACK, this parameter specifies the callback function or method. In other error modes this parameter is ignored.
string$userinfoIf you need to pass along for example debug information, this parameter is meant for that.
string$error_classThe returned error object will be instantiated from this class, if specified.
bool$skipmsgIf true, raiseError will only pass error codes, the error message parameter will be dropped.

@access public

Returns
object a PEAR error object
See also
PEAR::setErrorHandling
Since
PHP 4.0.5

Definition at line 522 of file PEAR.php.

529 {
530 // The error is yet a PEAR error object
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();
537 }
538
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))) {
543 $mode = PEAR_ERROR_RETURN;
544 }
545 }
546 // No mode given, try global ones
547 if ($mode === null) {
548 // Class error handler
549 if (isset($this) && isset($this->_default_error_mode)) {
552 // Global error handler
553 } elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
554 $mode = $GLOBALS['_PEAR_default_error_mode'];
555 $options = $GLOBALS['_PEAR_default_error_options'];
556 }
557 }
558
559 if ($error_class !== null) {
560 $ec = $error_class;
561 } elseif (isset($this) && isset($this->_error_class)) {
563 } else {
564 $ec = 'PEAR_Error';
565 }
566 if (intval(PHP_VERSION) < 5) {
567 // little non-eval hack to fix bug #12147
568 if ($skipmsg) {
569 $a = new $ec($code, $mode, $options, $userinfo);
570 } else {
571 $a = new $ec($message, $code, $mode, $options, $userinfo);
572 }
573 // end patch
574
575 return $a;
576 }
577 if ($skipmsg) {
578 $a = new $ec($code, $mode, $options, $userinfo);
579 } else {
580 $a = new $ec($message, $code, $mode, $options, $userinfo);
581 }
582 return $a;
583 }
const PEAR_ERROR_RETURN
#+ ERROR constants
Definition: PEAR.php:31
$_error_class
Definition: PEAR.php:146
catch(Exception $e) $message

References $_default_error_mode, $_default_error_options, $_error_class, $code, $GLOBALS, $message, PHPMailer\PHPMailer\$options, and PEAR_ERROR_RETURN.

Referenced by delExpect(), ilIndependentTemplate\getFile(), and throwError().

+ Here is the caller graph for this function:

◆ registerShutdownFunc()

PEAR::registerShutdownFunc (   $func,
  $args = array() 
)

Use this function to register a shutdown method for static classes.

@access public

Parameters
mixed$funcThe function name (or array of class/method) to call
mixed$argsThe arguments to pass to the function
Returns
void

Definition at line 255 of file PEAR.php.

256 {
257 // if we are called statically, there is a potential
258 // that no shutdown func is registered. Bug #6445
259 if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
260 register_shutdown_function("_PEAR_call_destructors");
261 $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
262 }
263 $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
264 }

References $GLOBALS.

◆ setErrorHandling()

static PEAR::setErrorHandling (   $mode = null,
  $options = null 
)
static

Sets how errors generated by this object should be handled.

Can be invoked both in objects and statically. If called statically, setErrorHandling sets the default behaviour for all PEAR objects. If called in an object, setErrorHandling sets the default behaviour for that object.

Parameters
int$modeOne of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT, PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE, PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION.
mixed$optionsWhen $mode is PEAR_ERROR_TRIGGER, this is the error level (one of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).

When $mode is PEAR_ERROR_CALLBACK, this parameter is expected to be the callback function or method. A callback function is a string with the name of the function, a callback method is an array of two elements: the element at index 0 is the object, and the element at index 1 is the name of the method to call in the object.

When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is a printf format string used when printing the error message.

@access public

Returns
void
See also
PEAR_ERROR_RETURN
PEAR_ERROR_PRINT
PEAR_ERROR_TRIGGER
PEAR_ERROR_DIE
PEAR_ERROR_CALLBACK
PEAR_ERROR_EXCEPTION
Since
PHP 4.0.5

Definition at line 337 of file PEAR.php.

338 {
339 $setmode = &$GLOBALS['_PEAR_default_error_mode'];
340 $setoptions = &$GLOBALS['_PEAR_default_error_options'];
341
342
343 switch ($mode) {
346 case PEAR_ERROR_PRINT:
348 case PEAR_ERROR_DIE:
349 case null:
350 $setmode = $mode;
351 $setoptions = $options;
352 break;
353
355 $setmode = $mode;
356 // class/object method callback
357 if (is_callable($options)) {
358 $setoptions = $options;
359 } else {
360 trigger_error("invalid error callback", E_USER_WARNING);
361 }
362 break;
363
364 default:
365 trigger_error("invalid error mode", E_USER_WARNING);
366 break;
367 }
368 }
const PEAR_ERROR_PRINT
Definition: PEAR.php:32
const PEAR_ERROR_TRIGGER
Definition: PEAR.php:33
const PEAR_ERROR_EXCEPTION
WARNING: obsolete.
Definition: PEAR.php:40
const PEAR_ERROR_CALLBACK
Definition: PEAR.php:35
const PEAR_ERROR_DIE
Definition: PEAR.php:34

References $GLOBALS, PHPMailer\PHPMailer\$options, PEAR_ERROR_CALLBACK, PEAR_ERROR_DIE, PEAR_ERROR_EXCEPTION, PEAR_ERROR_PRINT, PEAR_ERROR_RETURN, and PEAR_ERROR_TRIGGER.

Referenced by popErrorHandling(), and pushErrorHandling().

+ Here is the caller graph for this function:

◆ staticPopErrorHandling()

PEAR::staticPopErrorHandling ( )

Definition at line 644 of file PEAR.php.

645 {
646 $stack = &$GLOBALS['_PEAR_error_handler_stack'];
647 $setmode = &$GLOBALS['_PEAR_default_error_mode'];
648 $setoptions = &$GLOBALS['_PEAR_default_error_options'];
649 array_pop($stack);
650 list($mode, $options) = $stack[sizeof($stack) - 1];
651 array_pop($stack);
652 switch ($mode) {
655 case PEAR_ERROR_PRINT:
657 case PEAR_ERROR_DIE:
658 case null:
659 $setmode = $mode;
660 $setoptions = $options;
661 break;
662
664 $setmode = $mode;
665 // class/object method callback
666 if (is_callable($options)) {
667 $setoptions = $options;
668 } else {
669 trigger_error("invalid error callback", E_USER_WARNING);
670 }
671 break;
672
673 default:
674 trigger_error("invalid error mode", E_USER_WARNING);
675 break;
676 }
677 return true;
678 }

References $GLOBALS, PHPMailer\PHPMailer\$options, PEAR_ERROR_CALLBACK, PEAR_ERROR_DIE, PEAR_ERROR_EXCEPTION, PEAR_ERROR_PRINT, PEAR_ERROR_RETURN, and PEAR_ERROR_TRIGGER.

◆ staticPushErrorHandling()

PEAR::staticPushErrorHandling (   $mode,
  $options = null 
)

Definition at line 609 of file PEAR.php.

610 {
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);
615 switch ($mode) {
618 case PEAR_ERROR_PRINT:
620 case PEAR_ERROR_DIE:
621 case null:
622 $def_mode = $mode;
623 $def_options = $options;
624 break;
625
627 $def_mode = $mode;
628 // class/object method callback
629 if (is_callable($options)) {
630 $def_options = $options;
631 } else {
632 trigger_error("invalid error callback", E_USER_WARNING);
633 }
634 break;
635
636 default:
637 trigger_error("invalid error mode", E_USER_WARNING);
638 break;
639 }
640 $stack[] = array($mode, $options);
641 return true;
642 }

References $GLOBALS, PHPMailer\PHPMailer\$options, PEAR_ERROR_CALLBACK, PEAR_ERROR_DIE, PEAR_ERROR_EXCEPTION, PEAR_ERROR_PRINT, PEAR_ERROR_RETURN, and PEAR_ERROR_TRIGGER.

◆ throwError()

& PEAR::throwError (   $message = null,
  $code = null,
  $userinfo = null 
)

Simpler form of raiseError with fewer options.

In most cases message, code and userinfo are enough.

Parameters
string$message

Definition at line 595 of file PEAR.php.

598 {
599 if (isset($this) && is_a($this, 'PEAR')) {
600 $a = &$this->raiseError($message, $code, null, null, $userinfo);
601 return $a;
602 } else {
603 $a = &PEAR::raiseError($message, $code, null, null, $userinfo);
604 return $a;
605 }
606 }

References $code, $message, and raiseError().

+ Here is the call graph for this function:

Field Documentation

◆ $_debug

PEAR::$_debug = false

Definition at line 112 of file PEAR.php.

◆ $_default_error_handler

PEAR::$_default_error_handler = ''

Definition at line 138 of file PEAR.php.

◆ $_default_error_mode

PEAR::$_default_error_mode = null

Definition at line 120 of file PEAR.php.

Referenced by pushErrorHandling(), and raiseError().

◆ $_default_error_options

PEAR::$_default_error_options = null

Definition at line 129 of file PEAR.php.

Referenced by pushErrorHandling(), and raiseError().

◆ $_error_class

PEAR::$_error_class = 'PEAR_Error'

Definition at line 146 of file PEAR.php.

Referenced by raiseError().

◆ $_expected_errors

PEAR::$_expected_errors = array()

Definition at line 154 of file PEAR.php.

Referenced by expectError().


The documentation for this class was generated from the following file: