Make WordPress Core

Changeset 59109


Ignore:
Timestamp:
09/27/2024 07:58:49 PM (9 months ago)
Author:
hellofromTonya
Message:

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:

Follow-up to [25002].

Props jrf.
See #62061.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/utils.php

    r59055 r59109  
    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 );
Note: See TracChangeset for help on using the changeset viewer.