From c2afd4efc08d050595c29c74917ea54176f51a22 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 6 Dec 2011 12:36:03 +0100 Subject: [PATCH] moved custom errorHandler to avoid XML Feed declaring and callback errors --- include/compat.inc.php | 31 +++++++++++++++++++++++++++++++ serendipity_config.inc.php | 34 +++++++--------------------------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/include/compat.inc.php b/include/compat.inc.php index 1dd4bebd..0aa23716 100644 --- a/include/compat.inc.php +++ b/include/compat.inc.php @@ -67,6 +67,37 @@ function memSnap($tshow = '') { $memUsage = $current; } +/** + * Set our own exeption handler to convert all errors into exeptions automatically + * function_exists() avoids 'cannot redeclare previously declared' fatal errors in XML feed context + * + * @access public + * @param standard + * @return null + */ +if(!function_exists('errorToExceptionHandler')) { + function errorToExceptionHandler($errNo, $errStr, $errFile, $errLine, $errContext) { + // ToDo: enhance for special serendipity error needs, + // like $errContext or specify tracing off in user context + // @disabled errors will not appear + + $rep = ini_get('error_reporting'); + // function error handler must return false to support $php_errormsg messages + if(!($rep & $errStr)) { return false; } + // respect user has set php to not display errors at all + // may be overridden by if(ini_get('display_errors') == 0) print error in further context + elseif (error_reporting() == 0) { return; } + // throw errors as exception + else { + if($serendipity['production'] !== true) echo ' == DEBUG MODE == '; + echo '
';
+            throw new ErrorException($errStr, 0, $errNo, $errFile, $errLine);
+            echo '
'; + } + return true; + } +} + if (!function_exists('file_get_contents')) { function file_get_contents($filename, $use_include_path = 0) { $file = fopen($filename, 'rb', $use_include_path); diff --git a/serendipity_config.inc.php b/serendipity_config.inc.php index bf6cea6f..7db81737 100644 --- a/serendipity_config.inc.php +++ b/serendipity_config.inc.php @@ -6,8 +6,6 @@ if (defined('S9Y_FRAMEWORK')) { return; } -set_error_handler('errorToExceptionHandler', E_ALL & ~E_NOTICE); - @define('S9Y_FRAMEWORK', true); if (!headers_sent()) { @@ -62,31 +60,13 @@ if ($serendipity['production'] !== true) { @ini_set('display_errors', 'on'); } -/** - * Set our own exeption handler to convert all errors into exeptions automatically - * - * @access public - * @param standard - * @return null - */ -function errorToExceptionHandler($errNo, $errStr, $errFile, $errLine, $errContext) { - // ToDo: enhance for special serendipity error needs, - // like $errContext or specify tracing off in user context - // @disabled errors will not appear - - $rep = ini_get('error_reporting'); - // function error handler must return false to support $php_errormsg - if(!($rep & $errStr)) { return false; } - // respect user has set php to not display errors at all - // may be overridden by if(ini_get('display_errors') == 0) print error in further context - elseif (error_reporting() == 0) { return; } - else { - if($serendipity['production'] !== true) echo ' == DEBUG MODE == '; - echo '
';
-        throw new ErrorException($errStr, 0, $errNo, $errFile, $errLine);
-        echo '
'; - } - return true; +// The serendipity errorhandler string +$serendipity['errorhandler'] = 'errorToExceptionHandler'; + +//[internal callback function]: errorToExceptionHandler() +if(is_callable($serendipity['errorhandler'], false, $callable_name)) { + // set serendipity global error to exeption handler + set_error_handler($serendipity['errorhandler'], E_ALL & ~E_NOTICE); } // Default rewrite method