From a21f9d49e013778650b997a0ad3444f01fd364d7 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 13 Apr 2005 23:53:18 +0000 Subject: [PATCH] Updated error reporting stuff. It was really broken before and I'm not exactly sure why. We now also use the pre-defined PHP constants instead of the ERR_* ones. --- kernel.php | 64 +++++++++++++++++++++++++++---------------------- template.php | 6 ++--- template_fs.php | 6 ++--- xml.php | 2 +- 4 files changed, 42 insertions(+), 36 deletions(-) diff --git a/kernel.php b/kernel.php index 7aa1052..3b182ce 100644 --- a/kernel.php +++ b/kernel.php @@ -10,13 +10,9 @@ || ################################################################### || \*=====================================================================*/ -define('ERR_FATAL', E_USER_ERROR); -define('ERR_ALERT', E_USER_WARNING); -define('ERR_WARNING', E_USER_NOTICE); - if (PHP_VERSION < '4.1.0') { - trigger_error('You need PHP version 4.1.0 or newer to run ISSO', ERR_FATAL); + trigger_error('You need PHP version 4.1.0 or newer to run ISSO', E_USER_ERROR); exit; } @@ -32,20 +28,29 @@ if (version_compare(PHP_VERSION, '5.0.0', '>=')) } } -if (!(ini_get('error_reporting') & E_NOTICE) AND ini_get('error_reporting') & E_USER_NOTICE) +$oldlevel = ini_get('error_reporting'); +$newlevel = $oldlevel; +$levels = array(E_ERROR => E_USER_ERROR, E_WARNING => E_USER_WARNING, E_NOTICE => E_USER_NOTICE); +foreach ($levels AS $php => $isso) { - error_reporting(ini_get('error_reporting') - E_USER_NOTICE); -} - -if (!(ini_get('error_reporting') & E_WARNING) AND ini_get('error_reporting') & E_USER_WARNING) -{ - error_reporting(ini_get('error_reporting') - E_USER_WARNING); -} - -if (!(ini_get('error_reporting') & E_ERROR) AND ini_get('error_reporting') & E_USER_ERROR) -{ - error_reporting(ini_get('error_reporting') - E_USER_ERROR); + if ($oldlevel & $php) + { + if (!($oldlevel & $isso)) + { + echo "increasing newlevel by $isso; "; + $newlevel += $isso; + } + } + else + { + if ($oldlevel & $isso) + { + echo "decreasing newlevel by $isso; "; + $newlevel -= $isso; + } + } } +error_reporting($newlevel); if ((bool)ini_get('register_globals') === true) { @@ -184,7 +189,7 @@ class Shared_Object_Framework { if ($this->sourcepath == '') { - trigger_error('Invalid sourcepath specified', ERR_FATAL); + trigger_error('Invalid sourcepath specified', E_USER_ERROR); } if (file_exists($this->sourcepath . $framework . '.php')) @@ -194,7 +199,7 @@ class Shared_Object_Framework } else { - trigger_error('Could not find the framework ' . $this->sourcepath . $framework . '.php', ERR_FATAL); + trigger_error('Could not find the framework ' . $this->sourcepath . $framework . '.php', E_USER_ERROR); exit; } } @@ -291,6 +296,7 @@ class Shared_Object_Framework /** * Custom error handler for ISSO + * We only handle E_WARNING, E_NOTICE, E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE * * @param int Error number * @param str Error message string @@ -303,28 +309,28 @@ class Shared_Object_Framework switch ($errno) { // Fatal - case ERR_FATAL: + case E_USER_ERROR: $title = 'Fatal'; - if (!(ini_get('error_reporting') & ERR_FATAL)) + if (!(ini_get('error_reporting') & E_USER_ERROR)) { return; } break; // Error - case ERR_ALERT: - $title = 'Alert'; - if (!(ini_get('error_reporting') & ERR_ALERT)) + case E_USER_WARNING: + $title = 'Warning'; + if (!(ini_get('error_reporting') & E_USER_WARNING) AND !(ini_get('error_reporting') & E_WARNING)) { return; } break; // Warning - case ERR_WARNING: + case E_USER_NOTICE: default: - $title = 'Warning'; - if (!(ini_get('error_reporting') & ERR_WARNING)) + $title = 'Notice'; + if (!(ini_get('error_reporting') & E_USER_NOTICE) AND !(ini_get('error_reporting') & E_NOTICE)) { return; } @@ -337,7 +343,7 @@ class Shared_Object_Framework $this->_message($title, $errstr, 3); - if ($errno == ERR_FATAL) + if ($errno == E_USER_ERROR) { exit; } @@ -507,7 +513,7 @@ if (defined('ISSO_CHECK_POST_REFERER')) if ($ourhost != $host) { - trigger_error('No external hosts are allowed to POST to this application', ERR_FATAL); + trigger_error('No external hosts are allowed to POST to this application', E_USER_ERROR); } $_isso->debug('remote post check = ok'); } diff --git a/template.php b/template.php index 2c7056e..6ed1086 100644 --- a/template.php +++ b/template.php @@ -127,7 +127,7 @@ class DB_Template if (empty($template)) { - trigger_error('There was no output to print', ERR_FATAL); + trigger_error('There was no output to print', E_USER_ERROR); exit; } @@ -147,7 +147,7 @@ class DB_Template if ($this->doneflush) { - trigger_error('A template has already been sent to the output buffer', ERR_FATAL); + trigger_error('A template has already been sent to the output buffer', E_USER_ERROR); exit; } @@ -294,7 +294,7 @@ class DB_Template } else { - trigger_error("The template '$name' could not be loaded", ERR_FATAL); + trigger_error("The template '$name' could not be loaded", E_USER_ERROR); exit; } } diff --git a/template_fs.php b/template_fs.php index 521625b..070f214 100644 --- a/template_fs.php +++ b/template_fs.php @@ -51,7 +51,7 @@ class FS_Template extends DB_Template { if (sizeof($this->cache) > 0) { - trigger_error('You cannot cache templates more than once per initialization', ERR_ALERT); + trigger_error('You cannot cache templates more than once per initialization', E_USER_WARNING); } else { @@ -84,13 +84,13 @@ class FS_Template extends DB_Template } else { - trigger_error("Could not load the template '$path'", ERR_FATAL); + trigger_error("Could not load the template '$path'", E_USER_ERROR); exit; } } else { - trigger_error("Could not load the template '$path'", ERR_FATAL); + trigger_error("Could not load the template '$path'", E_USER_ERROR); exit; } } diff --git a/xml.php b/xml.php index 796b85d..da6f20e 100644 --- a/xml.php +++ b/xml.php @@ -116,7 +116,7 @@ class XML_Parser } else { - trigger_error('Could not find the function [' . $this->taghandler["$tagname"] . '()] for the XML tag "' . $tagname . '"', ERR_FATAL); + trigger_error('Could not find the function [' . $this->taghandler["$tagname"] . '()] for the XML tag "' . $tagname . '"', E_USER_ERROR); } } -- 2.43.5