Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
/lib/pear/ -> PEAR.php (source)

Differences Between: [Versions 401 and 402] [Versions 401 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.

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

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!

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

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

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

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

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

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.

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

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

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

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

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

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

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

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.

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,
return: object   a PEAR error object

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.

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
return: object   a PEAR error object

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.

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

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.

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

_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.

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

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