diff --git a/ecrire/inc/utils.php b/ecrire/inc/utils.php index 778aff80d33ac7cd9b9ab6a36ac33cb9d759a03d..0256652cf018a0d523d58731869014a31dc2cb3e 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 124b6ab810c6f91022f2b5a8e9ce81b94284cf53..68324faeb62046ca95f3c595acb925a557ce4fa5 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 * @@ -28,9 +30,6 @@ if (defined('_ECRIRE_INC_VERSION')) { */ define('_ECRIRE_INC_VERSION', '1'); -# masquer les eventuelles erreurs sur les premiers define -error_reporting(E_ALL ^ E_NOTICE); - /** version PHP minimum exigee (cf. inc/utils) */ define('_PHP_MIN', '8.1.0'); define('_PHP_MAX', '8.2.99'); @@ -484,7 +483,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..3e9500617830289178525d53b091b25876b3b665 --- /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::user_deprecated(...), E_USER_DEPRECATED); + } + } + + /** Loger les `trigger_deprecated()` */ + private 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; + } +}