Skip to content

Commit

Permalink
Code Modernization: Fix trigger_error() with E_USER_ERROR deprecation…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
hellofromtonya committed Sep 27, 2024
1 parent 004379e commit a51f2e4
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions tests/phpunit/includes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,12 @@ public function __construct( $in ) {
public function parse( $in ) {
$parse = xml_parse( $this->xml, $in, true );
if ( ! $parse ) {
trigger_error(
throw new Exception(
sprintf(
'XML error: %s at line %d',
xml_error_string( xml_get_error_code( $this->xml ) ),
xml_get_current_line_number( $this->xml )
),
E_USER_ERROR
)
);
xml_parser_free( $this->xml );
}
Expand Down

0 comments on commit a51f2e4

Please sign in to comment.