From 6eb12f4cf49a4e759e32e7b21725c7fb6312f512 Mon Sep 17 00:00:00 2001 From: Gina Peter Bnayard Date: Fri, 9 Aug 2024 13:42:24 +0200 Subject: [PATCH] ext/core: Deprecate passing E_USER_ERROR to trigger_error() RFC: https://wiki.php.net/rfc/deprecations_php_8_4#deprecate_passing_e_user_error_to_trigger_error --- NEWS | 1 + UPGRADING | 2 ++ Zend/tests/bug33802.phpt | 10 +++++----- Zend/tests/fibers/fatal-error-in-fiber.phpt | 2 ++ Zend/tests/fibers/fatal-error-in-nested-fiber.phpt | 2 ++ .../fibers/fatal-error-with-multiple-fibers.phpt | 2 ++ Zend/tests/fibers/gh10437.phpt | 2 ++ Zend/tests/gh10695_7.phpt | 2 +- Zend/tests/gh13097_a.phpt | 2 ++ Zend/tests/nowdoc_015.phpt | 14 +++++++------- Zend/zend_builtin_functions.c | 5 +++++ ext/standard/tests/streams/gh8409.phpt | 9 +++++++-- ext/zend_test/tests/observer_error_02.phpt | 2 ++ ext/zend_test/tests/observer_error_05.phpt | 2 ++ tests/lang/error_2_exception_001.phpt | 4 ++-- 15 files changed, 44 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index 5e6f7abc0544f..d4ba415294df5 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,7 @@ PHP NEWS . Fixed bug GH-15140 (Missing variance check for abstract set with asymmetric type). (ilutov) . Fixed bug GH-15181 (Disabled output handler is flushed again). (cmb) + . Passing E_USER_ERROR to trigger_error() is now deprecated. (Girgias) - Date: . Constants SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING, and SUNFUNCS_RET_DOUBLE diff --git a/UPGRADING b/UPGRADING index 99516dbb1a318..2ccfe43849390 100644 --- a/UPGRADING +++ b/UPGRADING @@ -401,6 +401,8 @@ PHP 8.4 UPGRADE NOTES - Core: . Implicitly nullable parameter types are now deprecated. RFC: https://wiki.php.net/rfc/deprecate-implicitly-nullable-types + . Passing E_USER_ERROR to trigger_error() is now deprecated. + RFC: https://wiki.php.net/rfc/deprecations_php_8_4#deprecate_passing_e_user_error_to_trigger_error - Curl: . The CURLOPT_BINARYTRANSFER constant is deprecated. diff --git a/Zend/tests/bug33802.phpt b/Zend/tests/bug33802.phpt index d2f8cd736e39a..db266905c356b 100644 --- a/Zend/tests/bug33802.phpt +++ b/Zend/tests/bug33802.phpt @@ -2,15 +2,15 @@ Bug #33802 (throw Exception in error handler causes crash) --FILE-- start(); ?> --EXPECTF-- +Deprecated: Passing E_USER_ERROR to trigger_error() is deprecated since 8.4, throw an exception or call exit with a string message instead in %s on line %d + Fatal error: Fatal error in fiber in %sfatal-error-in-fiber.php on line %d diff --git a/Zend/tests/fibers/fatal-error-in-nested-fiber.phpt b/Zend/tests/fibers/fatal-error-in-nested-fiber.phpt index d012576aa2388..770c1d45a5a08 100644 --- a/Zend/tests/fibers/fatal-error-in-nested-fiber.phpt +++ b/Zend/tests/fibers/fatal-error-in-nested-fiber.phpt @@ -25,4 +25,6 @@ $fiber->resume(); int(2) int(1) +Deprecated: Passing E_USER_ERROR to trigger_error() is deprecated since 8.4, throw an exception or call exit with a string message instead in %s on line %d + Fatal error: Fatal error in nested fiber in %sfatal-error-in-nested-fiber.php on line %d diff --git a/Zend/tests/fibers/fatal-error-with-multiple-fibers.phpt b/Zend/tests/fibers/fatal-error-with-multiple-fibers.phpt index 8f66fba5e2c1e..875364c3f6b02 100644 --- a/Zend/tests/fibers/fatal-error-with-multiple-fibers.phpt +++ b/Zend/tests/fibers/fatal-error-with-multiple-fibers.phpt @@ -25,4 +25,6 @@ $fiber2->resume(); int(1) int(2) +Deprecated: Passing E_USER_ERROR to trigger_error() is deprecated since 8.4, throw an exception or call exit with a string message instead in %s on line %d + Fatal error: Fatal error in fiber in %sfatal-error-with-multiple-fibers.php on line %d diff --git a/Zend/tests/fibers/gh10437.phpt b/Zend/tests/fibers/gh10437.phpt index 5c793c986ee29..15321641ec9ef 100644 --- a/Zend/tests/fibers/gh10437.phpt +++ b/Zend/tests/fibers/gh10437.phpt @@ -14,5 +14,7 @@ $fiber->start(); ?> --EXPECTF-- +Deprecated: Passing E_USER_ERROR to trigger_error() is deprecated since 8.4, throw an exception or call exit with a string message instead in %s on line %d + Fatal error: Bailout in fiber in %sgh10437.php on line %d NULL diff --git a/Zend/tests/gh10695_7.phpt b/Zend/tests/gh10695_7.phpt index 12ec5fc454126..9eb2307ffc6d2 100644 --- a/Zend/tests/gh10695_7.phpt +++ b/Zend/tests/gh10695_7.phpt @@ -9,7 +9,7 @@ set_error_handler(function ($errno, $errstr) { throw new \Exception($errstr); }); register_shutdown_function(function () { - trigger_error('main', E_USER_ERROR); + trigger_error('main', E_USER_WARNING); }); ?> --EXPECT-- diff --git a/Zend/tests/gh13097_a.phpt b/Zend/tests/gh13097_a.phpt index b9ad729f66e4d..967bd18fec562 100644 --- a/Zend/tests/gh13097_a.phpt +++ b/Zend/tests/gh13097_a.phpt @@ -12,4 +12,6 @@ trigger_error( ?> --EXPECTF-- +Deprecated: Passing E_USER_ERROR to trigger_error() is deprecated since 8.4, throw an exception or call exit with a string message instead in %s on line %d + Fatal error: class@anonymous%s ...now you don't! in %s on line %d diff --git a/Zend/tests/nowdoc_015.phpt b/Zend/tests/nowdoc_015.phpt index 3b02273920967..ca24aa4fcc75c 100644 --- a/Zend/tests/nowdoc_015.phpt +++ b/Zend/tests/nowdoc_015.phpt @@ -6,25 +6,25 @@ function error_handler($num, $msg, $file, $line) { echo $line,"\n"; } set_error_handler('error_handler'); -trigger_error("line", E_USER_ERROR); +trigger_error("line", E_USER_WARNING); $x = << --EXPECT-- diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 9d2751a4a5856..23bc5f7a3cd57 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1214,6 +1214,11 @@ ZEND_FUNCTION(trigger_error) switch (error_type) { case E_USER_ERROR: + zend_error(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"); + if (UNEXPECTED(EG(exception))) { + RETURN_THROWS(); + } case E_USER_WARNING: case E_USER_NOTICE: case E_USER_DEPRECATED: diff --git a/ext/standard/tests/streams/gh8409.phpt b/ext/standard/tests/streams/gh8409.phpt index 7f0a28b183f81..35c0861c733ab 100644 --- a/ext/standard/tests/streams/gh8409.phpt +++ b/ext/standard/tests/streams/gh8409.phpt @@ -3,7 +3,7 @@ GH-8409: Error in socket creation when error handler does not clean persistent c --FILE-- --EXPECTF-- -Fatal error: stream_socket_client(): %s in %sgh8409.php on line %d +Fatal error: Uncaught Exception: stream_socket_client(): %s in %sgh8409.php:%d +Stack trace: +#0 [internal function]: {closure:%s:%d}(2, 'stream_socket_c...', '%s', %d) +#1 %s(%d): stream_socket_client('tcp://9999.9999...', 0, '', 0.2, 5) +#2 {main} + thrown in %s on line %d OK: persistent stream closed diff --git a/ext/zend_test/tests/observer_error_02.phpt b/ext/zend_test/tests/observer_error_02.phpt index f1c1500135b44..bcf1d560f2133 100644 --- a/ext/zend_test/tests/observer_error_02.phpt +++ b/ext/zend_test/tests/observer_error_02.phpt @@ -26,6 +26,8 @@ echo 'You should not see this.'; +Deprecated: Passing E_USER_ERROR to trigger_error() is deprecated since 8.4, throw an exception or call exit with a string message instead in %s on line %d + Fatal error: Foo error in %s on line %d diff --git a/ext/zend_test/tests/observer_error_05.phpt b/ext/zend_test/tests/observer_error_05.phpt index 361ac343c8ed2..d672e6405ec8c 100644 --- a/ext/zend_test/tests/observer_error_05.phpt +++ b/ext/zend_test/tests/observer_error_05.phpt @@ -35,6 +35,8 @@ echo 'You should not see this.'; +Deprecated: Passing E_USER_ERROR to trigger_error() is deprecated since 8.4, throw an exception or call exit with a string message instead in %s on line %d + Fatal error: Foo error in %s on line %d diff --git a/tests/lang/error_2_exception_001.phpt b/tests/lang/error_2_exception_001.phpt index 4dba9b7a1212e..f2e120f2685fd 100644 --- a/tests/lang/error_2_exception_001.phpt +++ b/tests/lang/error_2_exception_001.phpt @@ -30,11 +30,11 @@ try { } try { - trigger_error("I will become an exception", E_USER_ERROR); + trigger_error("I will become an exception", E_USER_WARNING); } catch (MyException $exception) { echo "There was an exception: " . $exception->getErrno() . ", '" . $exception->getErrmsg() . "'\n"; } ?> --EXPECT-- -There was an exception: 256, 'I will become an exception' +There was an exception: 512, 'I will become an exception'