Skip to content

Commit a51f2e4

Browse files
Code Modernization: Fix trigger_error() with E_USER_ERROR deprecation in TestXMLParser::parse().
PHP 8.4 deprecates the use of `trigger_errror()` with `E_USER_ERROR` as the error level, as there are a number of gotchas to this way of creating a `Fatal Error` (`finally` blocks not executing, destructors not executing). The recommended replacements are either to use exceptions or to do a hard `exit`. As this is a test-only class, do not have to take BC-breaks into account. Also, as this is a test helper, throwing a exception is the most appropriate solution. Reference: * https://wiki.php.net/rfc/deprecations_php_8_4#deprecate_passing_e_user_error_to_trigger_error Follow-up to [25002]. Props jrf. See #62061. git-svn-id: https://develop.svn.wordpress.org/trunk@59109 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 004379e commit a51f2e4

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

tests/phpunit/includes/utils.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,12 @@ public function __construct( $in ) {
304304
public function parse( $in ) {
305305
$parse = xml_parse( $this->xml, $in, true );
306306
if ( ! $parse ) {
307-
trigger_error(
307+
throw new Exception(
308308
sprintf(
309309
'XML error: %s at line %d',
310310
xml_error_string( xml_get_error_code( $this->xml ) ),
311311
xml_get_current_line_number( $this->xml )
312-
),
313-
E_USER_ERROR
312+
)
314313
);
315314
xml_parser_free( $this->xml );
316315
}

0 commit comments

Comments
 (0)