You are here

function PEAR_Error::PEAR_Error in Calendar Systems 5

PEAR_Error constructor

@access public

Parameters

string $message message:

int $code (optional) error code:

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

mixed $options (optional) error level, _OR_ in the case of: PEAR_ERROR_CALLBACK, the callback function or object/method tuple.

string $userinfo (optional) additional user/debug info:

File

calendar/lib/PEAR.php, line 856

Class

PEAR_Error
Standard PEAR error class for PHP 4

Code

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);');
  }
}