From 45515b707240e672bc1fb64082c7114506529daf Mon Sep 17 00:00:00 2001 From: rxu Date: Sun, 18 Aug 2024 18:08:42 +0700 Subject: [PATCH] [ticket/17384] Handle E_USER_ERROR for PHP 8.4 tests PHPBB-17384 --- tests/test_framework/phpbb_test_case.php | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test_framework/phpbb_test_case.php b/tests/test_framework/phpbb_test_case.php index 726f6671ae..cd71fcaf28 100644 --- a/tests/test_framework/phpbb_test_case.php +++ b/tests/test_framework/phpbb_test_case.php @@ -35,6 +35,8 @@ class phpbb_test_case extends TestCase 'phpbb_database_test_case' => ['already_connected', 'last_post_timestamp'], ]; $this->excludeBackupStaticAttributes($backupStaticAttributesBlacklist); + + set_error_handler([$this, 'trigger_error_callback']); } public function get_test_case_helpers() @@ -135,4 +137,31 @@ class phpbb_test_case extends TestCase parent::assertFileNotExists($filename, $message); } } + + /** + * Passing E_USER_ERROR to trigger_error() is deprecated as of PHP 8.4, so it causes E_DEPRECATED + * Use trigger_error() callback function to workaround this by handling E_USER_ERROR and suppressing E_DEPRECATED + * "Passing E_USER_ERROR to trigger_error() is deprecated since 8.4, throw an exception or call exit with a string message instead" + * + */ + public function trigger_error_callback($errno, $errstr, $errfile, $errline) + { + // $errstr may need to be escaped + $errstr = htmlspecialchars($errstr); + + switch ($errno) { + case E_USER_ERROR: + echo $errstr; + exit(); + break; + + case E_DEPRECATED: + return true; + break; + + default: + return false; + break; + } + } }