You are here

class PEAR_Error in Flickr API 5

Standard PEAR error class for PHP 4

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

@category pear @package PEAR @author Stig Bakken <ssb@php.net> @author Tomas V.V. Cox <cox@idecnet.com> @author Gregory Beaver <cellog@php.net> @copyright 1997-2006 The PHP Group @license http://www.php.net/license/3_0.txt PHP License 3.0 @version Release: 1.6.2 @link http://pear.php.net/manual/en/core.pear.pear-error.php @since Class available since PHP 4.0.2

Hierarchy

Expanded class hierarchy of PEAR_Error

See also

PEAR::raiseError(), PEAR::throwError()

2 string references to 'PEAR_Error'
PEAR::isError in phpFlickr/PEAR/PEAR.php
Tell whether a value is a PEAR error.
PEAR::raiseError in phpFlickr/PEAR/PEAR.php
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.

File

phpFlickr/PEAR/PEAR.php, line 821

View source
class PEAR_Error {

  // {{{ properties
  var $error_message_prefix = '';
  var $mode = PEAR_ERROR_RETURN;
  var $level = E_USER_NOTICE;
  var $code = -1;
  var $message = '';
  var $userinfo = '';
  var $backtrace = null;

  // }}}
  // {{{ constructor

  /**
   * PEAR_Error constructor
   *
   * @param string $message  message
   *
   * @param int $code     (optional) error code
   *
   * @param int $mode     (optional) error mode, one of: PEAR_ERROR_RETURN,
   * PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER,
   * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION
   *
   * @param mixed $options   (optional) error level, _OR_ in the case of
   * PEAR_ERROR_CALLBACK, the callback function or object/method
   * tuple.
   *
   * @param string $userinfo (optional) additional user/debug info
   *
   * @access public
   *
   */
  function PEAR_Error($message = 'unknown error', $code = null, $mode = null, $options = null, $userinfo = null) {
    if ($mode === null) {
      $mode = PEAR_ERROR_RETURN;
    }
    $this->message = $message;
    $this->code = $code;
    $this->mode = $mode;
    $this->userinfo = $userinfo;
    if (!PEAR::getStaticProperty('PEAR_Error', 'skiptrace')) {
      $this->backtrace = debug_backtrace();
      if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) {
        unset($this->backtrace[0]['object']);
      }
    }
    if ($mode & PEAR_ERROR_CALLBACK) {
      $this->level = E_USER_NOTICE;
      $this->callback = $options;
    }
    else {
      if ($options === null) {
        $options = E_USER_NOTICE;
      }
      $this->level = $options;
      $this->callback = null;
    }
    if ($this->mode & PEAR_ERROR_PRINT) {
      if (is_null($options) || is_int($options)) {
        $format = "%s";
      }
      else {
        $format = $options;
      }
      printf($format, $this
        ->getMessage());
    }
    if ($this->mode & PEAR_ERROR_TRIGGER) {
      trigger_error($this
        ->getMessage(), $this->level);
    }
    if ($this->mode & PEAR_ERROR_DIE) {
      $msg = $this
        ->getMessage();
      if (is_null($options) || is_int($options)) {
        $format = "%s";
        if (substr($msg, -1) != "\n") {
          $msg .= "\n";
        }
      }
      else {
        $format = $options;
      }
      die(sprintf($format, $msg));
    }
    if ($this->mode & PEAR_ERROR_CALLBACK) {
      if (is_callable($this->callback)) {
        call_user_func($this->callback, $this);
      }
    }
    if ($this->mode & PEAR_ERROR_EXCEPTION) {
      trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
      eval('$e = new Exception($this->message, $this->code);throw($e);');
    }
  }

  // }}}
  // {{{ getMode()

  /**
   * Get the error mode from an error object.
   *
   * @return int error mode
   * @access public
   */
  function getMode() {
    return $this->mode;
  }

  // }}}
  // {{{ getCallback()

  /**
   * Get the callback function/method from an error object.
   *
   * @return mixed callback function or object/method array
   * @access public
   */
  function getCallback() {
    return $this->callback;
  }

  // }}}
  // {{{ getMessage()

  /**
   * Get the error message from an error object.
   *
   * @return  string  full error message
   * @access public
   */
  function getMessage() {
    return $this->error_message_prefix . $this->message;
  }

  // }}}
  // {{{ getCode()

  /**
   * Get error code from an error object
   *
   * @return int error code
   * @access public
   */
  function getCode() {
    return $this->code;
  }

  // }}}
  // {{{ getType()

  /**
   * Get the name of this error/exception.
   *
   * @return string error/exception name (type)
   * @access public
   */
  function getType() {
    return get_class($this);
  }

  // }}}
  // {{{ getUserInfo()

  /**
   * Get additional user-supplied information.
   *
   * @return string user-supplied information
   * @access public
   */
  function getUserInfo() {
    return $this->userinfo;
  }

  // }}}
  // {{{ getDebugInfo()

  /**
   * Get additional debug information supplied by the application.
   *
   * @return string debug information
   * @access public
   */
  function getDebugInfo() {
    return $this
      ->getUserInfo();
  }

  // }}}
  // {{{ getBacktrace()

  /**
   * 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.
   * @access public
   */
  function getBacktrace($frame = null) {
    if (defined('PEAR_IGNORE_BACKTRACE')) {
      return null;
    }
    if ($frame === null) {
      return $this->backtrace;
    }
    return $this->backtrace[$frame];
  }

  // }}}
  // {{{ addUserInfo()
  function addUserInfo($info) {
    if (empty($this->userinfo)) {
      $this->userinfo = $info;
    }
    else {
      $this->userinfo .= " ** {$info}";
    }
  }

  // }}}
  // {{{ toString()

  /**
   * Make a string representation of this object.
   *
   * @return string a string with an object summary
   * @access public
   */
  function toString() {
    $modes = array();
    $levels = array(
      E_USER_NOTICE => 'notice',
      E_USER_WARNING => 'warning',
      E_USER_ERROR => 'error',
    );
    if ($this->mode & PEAR_ERROR_CALLBACK) {
      if (is_array($this->callback)) {
        $callback = (is_object($this->callback[0]) ? strtolower(get_class($this->callback[0])) : $this->callback[0]) . '::' . $this->callback[1];
      }
      else {
        $callback = $this->callback;
      }
      return sprintf('[%s: message="%s" code=%d mode=callback ' . 'callback=%s prefix="%s" info="%s"]', strtolower(get_class($this)), $this->message, $this->code, $callback, $this->error_message_prefix, $this->userinfo);
    }
    if ($this->mode & PEAR_ERROR_PRINT) {
      $modes[] = 'print';
    }
    if ($this->mode & PEAR_ERROR_TRIGGER) {
      $modes[] = 'trigger';
    }
    if ($this->mode & PEAR_ERROR_DIE) {
      $modes[] = 'die';
    }
    if ($this->mode & PEAR_ERROR_RETURN) {
      $modes[] = 'return';
    }
    return sprintf('[%s: message="%s" code=%d mode=%s level=%s ' . 'prefix="%s" info="%s"]', strtolower(get_class($this)), $this->message, $this->code, implode("|", $modes), $levels[$this->level], $this->error_message_prefix, $this->userinfo);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PEAR_Error::$backtrace property
PEAR_Error::$code property
PEAR_Error::$error_message_prefix property
PEAR_Error::$level property
PEAR_Error::$message property
PEAR_Error::$mode property
PEAR_Error::$userinfo property
PEAR_Error::addUserInfo function
PEAR_Error::getBacktrace function Get the call backtrace from where the error was generated. Supported with PHP 4.3.0 or newer.
PEAR_Error::getCallback function Get the callback function/method from an error object.
PEAR_Error::getCode function Get error code from an error object
PEAR_Error::getDebugInfo function Get additional debug information supplied by the application.
PEAR_Error::getMessage function Get the error message from an error object.
PEAR_Error::getMode function Get the error mode from an error object.
PEAR_Error::getType function Get the name of this error/exception.
PEAR_Error::getUserInfo function Get additional user-supplied information.
PEAR_Error::PEAR_Error function PEAR_Error constructor
PEAR_Error::toString function Make a string representation of this object.