Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
/lib/pear/ -> PEAR.php (source)

Differences Between: [Versions 400 and 402] [Versions 400 and 403]

PEAR, the PHP Extension and Application Repository PEAR class and PEAR_Error class

Author: Sterling Hughes <sterling@php.net>
Author: Stig Bakken <ssb@php.net>
Author: Tomas V.V.Cox <cox@idecnet.com>
Author: Greg Beaver <cellog@php.net>
Copyright: 1997-2010 The Authors
License: http://opensource.org/licenses/bsd-license.php New BSD License
Version: CVS: $Id$
File Size: 1083 lines (35 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 1 file
 lib/pear/PEAR5.php

Defines 3 classes

PEAR:: (19 methods):
  __construct()
  PEAR()
  _PEAR()
  getStaticProperty()
  registerShutdownFunc()
  isError()
  setErrorHandling()
  expectError()
  popExpect()
  _checkDelExpect()
  delExpect()
  raiseError()
  throwError()
  staticPushErrorHandling()
  staticPopErrorHandling()
  pushErrorHandling()
  popErrorHandling()
  loadExtension()
  _PEAR_call_destructors()

PEAR_Error:: (1 method):
  __construct()

PEAR_Exception:: (12 methods):
  PEAR_Error()
  getMode()
  getCallback()
  getMessage()
  getCode()
  getType()
  getUserInfo()
  getDebugInfo()
  getBacktrace()
  addUserInfo()
  __toString()
  toString()


Class: PEAR  - X-Ref

Base class for other PEAR classes.  Provides rudimentary
emulation of destructors.

If you want a destructor in your class, inherit PEAR and make a
destructor method called _yourclassname (same name as the
constructor, but with a "_" prefix).  Also, in your constructor you
have to call the PEAR constructor: $this->PEAR();.
The destructor method will be called without parameters.  Note that
at in some SAPI implementations (such as Apache), any output during
the request shutdown (in which destructors are called) seems to be
discarded.  If you need to get any debug information from your
destructor, use error_log(), syslog() or something similar.

IMPORTANT! To use the emulated destructors you need to create the
objects by reference: $obj =& new PEAR_child;

__construct($error_class = null)   X-Ref
Constructor.  Registers this object in
$_PEAR_destructor_object_list for destructor emulation if a
destructor object exists.

return: void
param: string $error_class  (optional) which class to use for

PEAR($error_class = null)   X-Ref
Only here for backwards compatibility.
E.g. Archive_Tar calls $this->PEAR() in its constructor.

param: string $error_class Which class to use for error objects,

_PEAR()   X-Ref
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.

return: void

getStaticProperty($class, $var)   X-Ref
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!

return: mixed   A reference to the variable. If not set it will be
param: string $class  The calling classname, to prevent clashes
param: string $var    The variable to retrieve.

registerShutdownFunc($func, $args = array()   X-Ref
Use this function to register a shutdown method for static
classes.

return: void
param: mixed $func  The function name (or array of class/method) to call
param: mixed $args  The arguments to pass to the function

isError($data, $code = null)   X-Ref
Tell whether a value is a PEAR error.

return: bool    true if parameter is an error
param: mixed $data   the value to test
param: int   $code   if $data is an error object, return true

setErrorHandling($mode = null, $options = null)   X-Ref
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.

return: void
param: int $mode
param: mixed $options

expectError($code = '*')   X-Ref
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

return: int     the new depth of the "expected errors" stack
param: mixed $code a single error code or an array of error codes to expect

popExpect()   X-Ref
This method pops one element off the expected error codes
stack.

return: array   the list of error codes that were popped

_checkDelExpect($error_code)   X-Ref
This method checks unsets an error code if available

return: bool true if the error code was unset, false otherwise
param: mixed error code

delExpect($error_code)   X-Ref
This method deletes all occurences of the specified element from
the expected error codes stack.

return: mixed list of error codes that were deleted or error
param: mixed $error_code error code that should be deleted

raiseError($message = null,$code = null,$mode = null,$options = null,$userinfo = null,$error_class = null,$skipmsg = false)   X-Ref
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.

return: object   a PEAR error object
param: mixed $message a text error message or a PEAR error object
param: int $code      a numeric error code (it is up to your class
param: int $mode      One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
param: mixed $options If $mode is PEAR_ERROR_TRIGGER, this parameter
param: string $userinfo If you need to pass along for example debug
param: string $error_class The returned error object will be
param: bool $skipmsg If true, raiseError will only pass error codes,

throwError($message = null, $code = null, $userinfo = null)   X-Ref
Simpler form of raiseError with fewer options.  In most cases
message, code and userinfo are enough.

return: object   a PEAR error object
param: mixed $message a text error message or a PEAR error object
param: int $code      a numeric error code (it is up to your class
param: string $userinfo If you need to pass along for example debug

staticPushErrorHandling($mode, $options = null)   X-Ref
No description

staticPopErrorHandling()   X-Ref
No description

pushErrorHandling($mode, $options = null)   X-Ref
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.

return: bool Always true
param: mixed $mode (same as setErrorHandling)
param: mixed $options (same as setErrorHandling)

popErrorHandling()   X-Ref
Pop the last error handler used

return: bool Always true

loadExtension($ext)   X-Ref
OS independant PHP extension load. Remember to take care
on the correct extension name for case sensitive OSes.

return: bool Success or not on the dl() call
param: string $ext The extension name

_PEAR_call_destructors()   X-Ref
No description

Class: PEAR_Error  - X-Ref

Standard PEAR error class for PHP 4

This class is supserseded by {@link PEAR_Exception} in PHP 5

__construct($message = 'unknown error', $code = null,$mode = null, $options = null, $userinfo = null)   X-Ref
PEAR_Error constructor

param: string $message  message
param: int $code     (optional) error code
param: int $mode     (optional) error mode, one of: PEAR_ERROR_RETURN,
param: mixed $options   (optional) error level, _OR_ in the case of
param: string $userinfo (optional) additional user/debug info

Class: PEAR_Exception  - X-Ref

PEAR_Error($message = 'unknown error', $code = null,$mode = null, $options = null, $userinfo = null)   X-Ref
Old syntax of class constructor for backward compatibility.


getMode()   X-Ref
Get the error mode from an error object.

return: int error mode

getCallback()   X-Ref
Get the callback function/method from an error object.

return: mixed callback function or object/method array

getMessage()   X-Ref
Get the error message from an error object.

return: string  full error message

getCode()   X-Ref
Get error code from an error object

return: int error code

getType()   X-Ref
Get the name of this error/exception.

return: string error/exception name (type)

getUserInfo()   X-Ref
Get additional user-supplied information.

return: string user-supplied information

getDebugInfo()   X-Ref
Get additional debug information supplied by the application.

return: string debug information

getBacktrace($frame = null)   X-Ref
Get the call backtrace from where the error was generated.
Supported with PHP 4.3.0 or newer.

return: array Backtrace, or NULL if not available.
param: int $frame (optional) what frame to fetch

addUserInfo($info)   X-Ref
No description

__toString()   X-Ref
No description

toString()   X-Ref
Make a string representation of this object.

return: string a string with an object summary