diff --git a/ecrire/inc/utils.php b/ecrire/inc/utils.php index 7c3775cd897f116c0bb3c2b1704018947028999d..79ffd9c88bf1d49c53c9b8ba2c6481bcf3ba0842 100644 --- a/ecrire/inc/utils.php +++ b/ecrire/inc/utils.php @@ -394,6 +394,7 @@ function spip_log($message = null, $name = null) { } } + /** * Enregistrement des journaux * diff --git a/ecrire/inc_version.php b/ecrire/inc_version.php index 53f6812381c3eb077322d2934709a0e86da87c15..5c292e6b726f30c509088401ba078d73248f8f33 100644 --- a/ecrire/inc_version.php +++ b/ecrire/inc_version.php @@ -9,6 +9,8 @@ * Ce programme est un logiciel libre distribué sous licence GNU/GPL. * \***************************************************************************/ +use Spip\ErrorHandler; + /** * Initialisation de SPIP * @@ -484,7 +486,8 @@ if (!defined('SPIP_ERREUR_REPORT')) { /** Masquer les warning */ define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED); } -error_reporting(SPIP_ERREUR_REPORT); + +ErrorHandler::setup(SPIP_ERREUR_REPORT); // Initialisations critiques non surchargeables par les plugins // INITIALISER LES REPERTOIRES NON PARTAGEABLES ET LES CONSTANTES diff --git a/ecrire/src/ErrorHandler.php b/ecrire/src/ErrorHandler.php new file mode 100644 index 0000000000000000000000000000000000000000..c024de84eda503775e2913bbc908ebd15a5ecf8b --- /dev/null +++ b/ecrire/src/ErrorHandler.php @@ -0,0 +1,40 @@ +<?php + +namespace Spip; + +/** + * Gestion des erreurs PHP + * @internal + */ +final class ErrorHandler { + + static bool $done = false; + + public static function setup(?int $error_level = null): void { + if (!self::$done) { + self::$done = true; + error_reporting($error_level); + set_error_handler(self::class . '::user_deprecated', E_USER_DEPRECATED); + } + } + + /** Loger les `trigger_deprecated()` */ + public static function user_deprecated(int $errno, string $errstr, string $errfile, int $errline): bool { + if (!(\E_USER_DEPRECATED & $errno)) { + return false; + } + + $backtrace = debug_backtrace(); + array_shift($backtrace); + do { + $t = array_shift($backtrace); + $fqdn = $t['class'] . $t['type'] . $t['function']; + } while (in_array($fqdn, ['trigger_error', 'trigger_deprecation'])); + + $errfile = $t['file']; + $errline = $t['line']; + + spip_log(sprintf('%s in %s on line %s', $errstr, $errfile, $errline), 'deprecated.' . _LOG_INFO); + return false; + } +}