3 * base include file for SimpleTest
5 * @subpackage UnitTester
6 * @version $Id: errors.php,v 1.12 2004/08/08 13:16:00 lastcraft Exp $
8 /** @ignore - PHP5 compatibility fix. */
9 if (! defined('E_STRICT')) {
10 define('E_STRICT', 2048);
14 * Singleton error queue used to record trapped
17 * @subpackage UnitTester
19 class SimpleErrorQueue
{
23 * Starts with an empty queue.
26 function SimpleErrorQueue() {
31 * Adds an error to the front of the queue.
32 * @param $severity PHP error code.
33 * @param $message Text of error.
34 * @param $filename File error occoured in.
35 * @param $line Line number of error.
36 * @param $super_globals Hash of PHP super global arrays.
39 function add($severity, $message, $filename, $line, $super_globals) {
42 array($severity, $message, $filename, $line, $super_globals));
46 * Pulls the earliest error from the queue.
47 * @return False if none, or a list of error
48 * information. Elements are: severity
49 * as the PHP error code, the error message,
50 * the file with the error, the line number
51 * and a list of PHP super global arrays.
55 if (count($this->_queue
)) {
56 return array_shift($this->_queue
);
62 * Discards the contents of the error queue.
66 $this->_queue
= array();
70 * Tests to see if the queue is empty.
71 * @return True if empty.
74 return (count($this->_queue
) == 0);
78 * Global access to a single error queue.
79 * @return Global error queue object.
83 function &instance() {
84 static $queue = false
;
86 $queue = new SimpleErrorQueue();
92 * Converst an error code into it's string
94 * @param $severity PHP integer error code.
95 * @return String version of error code.
99 function getSeverityAsString($severity) {
101 E_STRICT
=> 'E_STRICT',
102 E_ERROR
=> 'E_ERROR',
103 E_WARNING
=> 'E_WARNING',
104 E_PARSE
=> 'E_PARSE',
105 E_NOTICE
=> 'E_NOTICE',
106 E_CORE_ERROR
=> 'E_CORE_ERROR',
107 E_CORE_WARNING
=> 'E_CORE_WARNING',
108 E_COMPILE_ERROR
=> 'E_COMPILE_ERROR',
109 E_COMPILE_WARNING
=> 'E_COMPILE_WARNING',
110 E_USER_ERROR
=> 'E_USER_ERROR',
111 E_USER_WARNING
=> 'E_USER_WARNING',
112 E_USER_NOTICE
=> 'E_USER_NOTICE');
113 return $map[$severity];
118 * Error handler that simply stashes any errors into the global
119 * error queue. Simulates the existing behaviour with respect to
120 * logging errors, but this feature may be removed in future.
121 * @param $severity PHP error code.
122 * @param $message Text of error.
123 * @param $filename File error occoured in.
124 * @param $line Line number of error.
125 * @param $super_globals Hash of PHP super global arrays.
129 function simpleTestErrorHandler($severity, $message, $filename, $line, $super_globals) {
130 restore_error_handler();
131 if (ini_get('log_errors')) {
132 $label = SimpleErrorQueue
::getSeverityAsString($severity);
133 error_log("$label: $message in $filename on line $line");
135 if ($severity = $severity & error_reporting()) {
136 $queue = &SimpleErrorQueue
::instance();
137 $queue->add($severity, $message, $filename, $line, $super_globals);
139 set_error_handler('simpleTestErrorHandler');