From 2bad6efd9c73007d0b88002af131f47f2ab3447b Mon Sep 17 00:00:00 2001 From: onli Date: Sat, 26 Jun 2021 16:49:21 +0200 Subject: [PATCH] Hide PHP warnings in production mode (#765) * Hide PHP warnings in production mode * Silence error reporing during second language file read --- docs/NEWS | 4 +++- include/plugin_api.inc.php | 10 ++++++++-- serendipity_config.inc.php | 6 +++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/NEWS b/docs/NEWS index 0a89a356..49f328fb 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -1,3 +1,5 @@ + * Hide more PHP warnings in production mode, to ease the migration + to PHP 8 * Fix: Deleting a user was not possible * New images added via the ML will set loading="lazy", improving site performance for visitors (only if height and width known) @@ -11,7 +13,7 @@ * Change backend_image_add hook to always contain same structure * Split date and time input in editor into two input fields * Improve performance of the media library by caching the file list - + Version 2.4-alpha2 () ------------------------------------------------------------------------ * Adds 'image_id' to event 'backend_image_add' in addData array diff --git a/include/plugin_api.inc.php b/include/plugin_api.inc.php index b6ccc7a4..cb050f11 100644 --- a/include/plugin_api.inc.php +++ b/include/plugin_api.inc.php @@ -1305,12 +1305,18 @@ class serendipity_plugin_api static function load_language($path) { global $serendipity; + // We deactivate error reporting here, because in PHP 8 setting constants twice always throws a warning. + // However, the language files of some plugins sometimes rely on constants being set only in the fallback + // language file, so we do have to set the other constants twice. + $oldReportingLevel = error_reporting(); + error_reporting(0); + $probelang = $path . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php'; if (file_exists($probelang)) { include $probelang; - } else { - include $path . '/lang_en.inc.php'; } + include $path . '/lang_en.inc.php'; + error_reporting($oldReportingLevel); } } diff --git a/serendipity_config.inc.php b/serendipity_config.inc.php index cc5eb3d7..6876a7f8 100644 --- a/serendipity_config.inc.php +++ b/serendipity_config.inc.php @@ -60,7 +60,11 @@ if (!isset($serendipity['production'])) { } // Set error reporting -error_reporting(E_ALL & ~(E_NOTICE|E_STRICT|E_DEPRECATED)); // is 22519 with 5.4+ +if ($serendipity['production']) { + error_reporting(E_ALL & ~(E_WARNING|E_NOTICE|E_STRICT|E_DEPRECATED)); +} else { + error_reporting(E_ALL & ~(E_NOTICE|E_STRICT|E_DEPRECATED)); +} if ($serendipity['production'] !== true) { @ini_set('display_errors', 'on');