Bearsampp 2026.9.23
Loading...
Searching...
No Matches
PEAR_Exception Class Reference
Inheritance diagram for PEAR_Exception:
Collaboration diagram for PEAR_Exception:

Public Member Functions

 __construct ($message, $p2=null, $p3=null)
 __toString ()
 getCause ()
 getCauseMessage (&$causes)
 getErrorClass ()
 getErrorData ()
 getErrorMethod ()
 getTraceSafe ()
 toHtml ()
 toText ()

Static Public Member Functions

static addObserver ($callback, $label='default')
static getUniqueId ()
static removeObserver ($label='default')

Data Fields

const OBSERVER_DIE = -8
const OBSERVER_PRINT = -2
const OBSERVER_TRIGGER = -4

Protected Attributes

 $cause

Private Member Functions

 signal ()

Private Attributes

 $_trace

Static Private Attributes

static $_observers = array()
static $_uniqueid = 0

Detailed Description

Definition at line 96 of file Exception.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( $message,
$p2 = null,
$p3 = null )

Supported signatures:

Definition at line 120 of file Exception.php.

121 {
122 if (is_int($p2)) {
123 $code = $p2;
124 $this->cause = null;
125 } elseif (is_object($p2) || is_array($p2)) {
126 // using is_object allows both Exception and PEAR_Error
127 if (is_object($p2) && !($p2 instanceof Exception)) {
128 if (!class_exists('PEAR_Error') || !($p2 instanceof PEAR_Error)) {
129 throw new PEAR_Exception('exception cause must be Exception, ' .
130 'array, or PEAR_Error');
131 }
132 }
133 $code = $p3;
134 if (is_array($p2) && isset($p2['message'])) {
135 // fix potential problem of passing in a single warning
136 $p2 = array($p2);
137 }
138 $this->cause = $p2;
139 } else {
140 $code = null;
141 $this->cause = null;
142 }
143 parent::__construct($message, $code);
144 $this->signal();
145 }

References signal().

Here is the call graph for this function:

Member Function Documentation

◆ __toString()

__toString ( )

Definition at line 314 of file Exception.php.

315 {
316 if (isset($_SERVER['REQUEST_URI'])) {
317 return $this->toHtml();
318 }
319 return $this->toText();
320 }

References toHtml(), and toText().

Here is the call graph for this function:

◆ addObserver()

addObserver ( $callback,
$label = 'default' )
static
Parameters
mixed$callback- A valid php callback, see php func is_callable()
  • A PEAR_Exception::OBSERVER_* constant
  • An array(const PEAR_Exception::OBSERVER_*, mixed $options)
string$labelThe name of the observer. Use this if you want to remove it later with removeObserver()

Definition at line 155 of file Exception.php.

156 {
157 self::$_observers[$label] = $callback;
158 }

◆ getCause()

getCause ( )

Returns the exception that caused this exception to be thrown @access public

Returns
Exception|array The context of the exception

Definition at line 224 of file Exception.php.

225 {
226 return $this->cause;
227 }

References $cause.

◆ getCauseMessage()

getCauseMessage ( & $causes)

Function must be public to call on caused exceptions

Parameters
array

Definition at line 233 of file Exception.php.

234 {
235 $trace = $this->getTraceSafe();
236 $cause = array('class' => get_class($this),
237 'message' => $this->message,
238 'file' => 'unknown',
239 'line' => 'unknown');
240 if (isset($trace[0])) {
241 if (isset($trace[0]['file'])) {
242 $cause['file'] = $trace[0]['file'];
243 $cause['line'] = $trace[0]['line'];
244 }
245 }
246 $causes[] = $cause;
247 if ($this->cause instanceof PEAR_Exception) {
248 $this->cause->getCauseMessage($causes);
249 } elseif ($this->cause instanceof Exception) {
250 $causes[] = array('class' => get_class($this->cause),
251 'message' => $this->cause->getMessage(),
252 'file' => $this->cause->getFile(),
253 'line' => $this->cause->getLine());
254 } elseif (class_exists('PEAR_Error') && $this->cause instanceof PEAR_Error) {
255 $causes[] = array('class' => get_class($this->cause),
256 'message' => $this->cause->getMessage(),
257 'file' => 'unknown',
258 'line' => 'unknown');
259 } elseif (is_array($this->cause)) {
260 foreach ($this->cause as $cause) {
261 if ($cause instanceof PEAR_Exception) {
262 $cause->getCauseMessage($causes);
263 } elseif ($cause instanceof Exception) {
264 $causes[] = array('class' => get_class($cause),
265 'message' => $cause->getMessage(),
266 'file' => $cause->getFile(),
267 'line' => $cause->getLine());
268 } elseif (class_exists('PEAR_Error') && $cause instanceof PEAR_Error) {
269 $causes[] = array('class' => get_class($cause),
270 'message' => $cause->getMessage(),
271 'file' => 'unknown',
272 'line' => 'unknown');
273 } elseif (is_array($cause) && isset($cause['message'])) {
274 // PEAR_ErrorStack warning
275 $causes[] = array(
276 'class' => $cause['package'],
277 'message' => $cause['message'],
278 'file' => isset($cause['context']['file']) ?
279 $cause['context']['file'] :
280 'unknown',
281 'line' => isset($cause['context']['line']) ?
282 $cause['context']['line'] :
283 'unknown',
284 );
285 }
286 }
287 }
288 }

References $cause, and getTraceSafe().

Referenced by toHtml(), and toText().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getErrorClass()

getErrorClass ( )

Definition at line 302 of file Exception.php.

303 {
304 $trace = $this->getTraceSafe();
305 return $trace[0]['class'];
306 }

References getTraceSafe().

Here is the call graph for this function:

◆ getErrorData()

getErrorData ( )

Return specific error information that can be used for more detailed error messages or translation.

This method may be overridden in child exception classes in order to add functionality not present in PEAR_Exception and is a placeholder to define API

The returned array must be an associative array of parameter => value like so:

array('name' => $name, 'context' => array(...))
Returns
array

Definition at line 214 of file Exception.php.

215 {
216 return array();
217 }

◆ getErrorMethod()

getErrorMethod ( )

Definition at line 308 of file Exception.php.

309 {
310 $trace = $this->getTraceSafe();
311 return $trace[0]['function'];
312 }

References getTraceSafe().

Here is the call graph for this function:

◆ getTraceSafe()

getTraceSafe ( )

Definition at line 290 of file Exception.php.

291 {
292 if (!isset($this->_trace)) {
293 $this->_trace = $this->getTrace();
294 if (empty($this->_trace)) {
295 $backtrace = debug_backtrace();
296 $this->_trace = array($backtrace[count($backtrace)-1]);
297 }
298 }
299 return $this->_trace;
300 }

References $_trace.

Referenced by getCauseMessage(), getErrorClass(), getErrorMethod(), and toHtml().

Here is the caller graph for this function:

◆ getUniqueId()

getUniqueId ( )
static
Returns
int unique identifier for an observer

Definition at line 168 of file Exception.php.

169 {
170 return self::$_uniqueid++;
171 }

◆ removeObserver()

removeObserver ( $label = 'default')
static

Definition at line 160 of file Exception.php.

161 {
162 unset(self::$_observers[$label]);
163 }

◆ signal()

signal ( )
private

Definition at line 173 of file Exception.php.

174 {
175 foreach (self::$_observers as $func) {
176 if (is_callable($func)) {
177 call_user_func($func, $this);
178 continue;
179 }
180 settype($func, 'array');
181 switch ($func[0]) {
182 case self::OBSERVER_PRINT :
183 $f = (isset($func[1])) ? $func[1] : '%s';
184 printf($f, $this->getMessage());
185 break;
186 case self::OBSERVER_TRIGGER :
187 $f = (isset($func[1])) ? $func[1] : E_USER_NOTICE;
188 trigger_error($this->getMessage(), $f);
189 break;
190 case self::OBSERVER_DIE :
191 $f = (isset($func[1])) ? $func[1] : '%s';
192 die(printf($f, $this->getMessage()));
193 break;
194 default:
195 trigger_error('invalid observer type', E_USER_WARNING);
196 }
197 }
198 }

Referenced by __construct().

Here is the caller graph for this function:

◆ toHtml()

toHtml ( )

Definition at line 322 of file Exception.php.

323 {
324 $trace = $this->getTraceSafe();
325 $causes = array();
326 $this->getCauseMessage($causes);
327 $html = '<table style="border: 1px" cellspacing="0">' . "\n";
328 foreach ($causes as $i => $cause) {
329 $html .= '<tr><td colspan="3" style="background: #ff9999">'
330 . str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: '
331 . htmlspecialchars($cause['message']) . ' in <b>' . $cause['file'] . '</b> '
332 . 'on line <b>' . $cause['line'] . '</b>'
333 . "</td></tr>\n";
334 }
335 $html .= '<tr><td colspan="3" style="background-color: #aaaaaa; text-align: center; font-weight: bold;">Exception trace</td></tr>' . "\n"
336 . '<tr><td style="text-align: center; background: #cccccc; width:20px; font-weight: bold;">#</td>'
337 . '<td style="text-align: center; background: #cccccc; font-weight: bold;">Function</td>'
338 . '<td style="text-align: center; background: #cccccc; font-weight: bold;">Location</td></tr>' . "\n";
339
340 foreach ($trace as $k => $v) {
341 $html .= '<tr><td style="text-align: center;">' . $k . '</td>'
342 . '<td>';
343 if (!empty($v['class'])) {
344 $html .= $v['class'] . $v['type'];
345 }
346 $html .= $v['function'];
347 $args = array();
348 if (!empty($v['args'])) {
349 foreach ($v['args'] as $arg) {
350 if (is_null($arg)) $args[] = 'null';
351 elseif (is_array($arg)) $args[] = 'Array';
352 elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')';
353 elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false';
354 elseif (is_int($arg) || is_double($arg)) $args[] = $arg;
355 else {
356 $arg = (string)$arg;
357 $str = htmlspecialchars(substr($arg, 0, 16));
358 if (strlen($arg) > 16) $str .= '&hellip;';
359 $args[] = "'" . $str . "'";
360 }
361 }
362 }
363 $html .= '(' . implode(', ',$args) . ')'
364 . '</td>'
365 . '<td>' . (isset($v['file']) ? $v['file'] : 'unknown')
366 . ':' . (isset($v['line']) ? $v['line'] : 'unknown')
367 . '</td></tr>' . "\n";
368 }
369 $html .= '<tr><td style="text-align: center;">' . ($k+1) . '</td>'
370 . '<td>{main}</td>'
371 . '<td>&nbsp;</td></tr>' . "\n"
372 . '</table>';
373 return $html;
374 }
getCauseMessage(&$causes)

References $cause, getCauseMessage(), and getTraceSafe().

Referenced by __toString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toText()

toText ( )

Definition at line 376 of file Exception.php.

377 {
378 $causes = array();
379 $this->getCauseMessage($causes);
380 $causeMsg = '';
381 foreach ($causes as $i => $cause) {
382 $causeMsg .= str_repeat(' ', $i) . $cause['class'] . ': '
383 . $cause['message'] . ' in ' . $cause['file']
384 . ' on line ' . $cause['line'] . "\n";
385 }
386 return $causeMsg . $this->getTraceAsString();
387 }

References $cause, and getCauseMessage().

Referenced by __toString().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ $_observers

$_observers = array()
staticprivate

Definition at line 102 of file Exception.php.

◆ $_trace

$_trace
private

Definition at line 104 of file Exception.php.

Referenced by getTraceSafe().

◆ $_uniqueid

$_uniqueid = 0
staticprivate

Definition at line 103 of file Exception.php.

◆ $cause

$cause
protected

Definition at line 101 of file Exception.php.

Referenced by getCause(), getCauseMessage(), toHtml(), and toText().

◆ OBSERVER_DIE

const OBSERVER_DIE = -8

Definition at line 100 of file Exception.php.

◆ OBSERVER_PRINT

const OBSERVER_PRINT = -2

Definition at line 98 of file Exception.php.

◆ OBSERVER_TRIGGER

const OBSERVER_TRIGGER = -4

Definition at line 99 of file Exception.php.


The documentation for this class was generated from the following file:
  • E:/Bearsampp-development/sandbox/core/libs/php/pear/pear/PEAR/Exception.php