Make WordPress Core


Ignore:
Timestamp:
09/11/2025 02:45:56 PM (11 months ago)
Author:
swissspidy
Message:

Code Modernization: Address reflection no-op function deprecations in PHP 8.5.

Reflection*::setAccessible() methods are no-ops since PHP 8.1. This commit adds conditional checks to only call these functions on older PHP versions.

Reference: PHP RFC: Deprecations for PHP 8.5: Deprecate `Reflection*::setAccessible()`.

Props rishabhwp, swissspidy.
Fixes #63956.
See #63061.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme/wpThemeJson.php

    r59814 r60729  
    24592459
    24602460                $func = $theme_json->getMethod( 'get_block_nodes' );
    2461                 $func->setAccessible( true );
     2461                if ( PHP_VERSION_ID < 81000 ) {
     2462                        $func->setAccessible( true );
     2463                }
    24622464
    24632465                $theme_json = array(
     
    25132515
    25142516                $func = $theme_json->getMethod( 'get_block_nodes' );
    2515                 $func->setAccessible( true );
     2517                if ( PHP_VERSION_ID < 81000 ) {
     2518                        $func->setAccessible( true );
     2519                }
    25162520
    25172521                $theme_json = array(
     
    38523856
    38533857                $get_property_value_method = $reflection_class->getMethod( 'get_property_value' );
    3854                 $get_property_value_method->setAccessible( true );
     3858                if ( PHP_VERSION_ID < 80100 ) {
     3859                        $get_property_value_method->setAccessible( true );
     3860                }
    38553861                $result = $get_property_value_method->invoke( null, $styles, $path );
    38563862
     
    58435849                );
    58445850                $reflection = new ReflectionMethod( $theme_json, 'process_blocks_custom_css' );
    5845                 $reflection->setAccessible( true );
     5851                if ( PHP_VERSION_ID < 80100 ) {
     5852                        $reflection->setAccessible( true );
     5853                }
    58465854
    58475855                $this->assertSame( $expected, $reflection->invoke( $theme_json, $input['css'], $input['selector'] ) );
     
    61786186
    61796187                $func = $theme_json->getMethod( 'get_block_style_variation_selector' );
    6180                 $func->setAccessible( true );
     6188                if ( PHP_VERSION_ID < 80100 ) {
     6189                        $func->setAccessible( true );
     6190                }
    61816191
    61826192                $actual = $func->invoke( null, 'custom', $selector );
     
    62606270
    62616271                $func = $theme_json->getMethod( 'scope_style_node_selectors' );
    6262                 $func->setAccessible( true );
     6272                if ( PHP_VERSION_ID < 80100 ) {
     6273                        $func->setAccessible( true );
     6274                }
    62636275
    62646276                $node = array(
     
    63096321
    63106322                $func = $theme_json->getMethod( 'get_block_nodes' );
    6311                 $func->setAccessible( true );
     6323                if ( PHP_VERSION_ID < 80100 ) {
     6324                        $func->setAccessible( true );
     6325                }
    63126326
    63136327                $theme_json = array(
     
    63456359
    63466360                $func = $theme_json->getMethod( 'get_block_nodes' );
    6347                 $func->setAccessible( true );
     6361                if ( PHP_VERSION_ID < 80100 ) {
     6362                        $func->setAccessible( true );
     6363                }
    63486364
    63496365                $theme_json = array(
Note: See TracChangeset for help on using the changeset viewer.