Make WordPress Core


Ignore:
Timestamp:
09/11/2025 02:45:56 PM (4 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/block-supports/duotone.php

    r57652 r60729  
    7979
    8080        $reflection = new ReflectionMethod( 'WP_Duotone', 'get_slug_from_attribute' );
    81         $reflection->setAccessible( true );
     81        if ( PHP_VERSION_ID < 80100 ) {
     82            $reflection->setAccessible( true );
     83        }
    8284
    8385        $this->assertSame( $expected, $reflection->invoke( null, $data_attr ) );
     
    129131        $wp_duotone                      = new WP_Duotone();
    130132        $block_css_declarations_property = new ReflectionProperty( 'WP_Duotone', 'block_css_declarations' );
    131         $block_css_declarations_property->setAccessible( true );
     133        if ( PHP_VERSION_ID < 80100 ) {
     134            $block_css_declarations_property->setAccessible( true );
     135        }
    132136        $previous_value = $block_css_declarations_property->getValue();
    133137        $block_css_declarations_property->setValue( $wp_duotone, array() );
     
    138142        // Reset the property.
    139143        $block_css_declarations_property->setValue( $wp_duotone, $previous_value );
    140         $block_css_declarations_property->setAccessible( false );
     144        if ( PHP_VERSION_ID < 80100 ) {
     145            $block_css_declarations_property->setAccessible( false );
     146        }
    141147
    142148        $this->assertNotEmpty( $actual );
     
    148154    public function test_is_preset( $data_attr, $expected ) {
    149155        $reflection = new ReflectionMethod( 'WP_Duotone', 'is_preset' );
    150         $reflection->setAccessible( true );
     156        if ( PHP_VERSION_ID < 80100 ) {
     157            $reflection->setAccessible( true );
     158        }
    151159
    152160        $this->assertSame( $expected, $reflection->invoke( null, $data_attr ) );
     
    174182    public function test_colord_parse_hue( $value, $unit, $expected ) {
    175183        $reflection = new ReflectionMethod( 'WP_Duotone', 'colord_parse_hue' );
    176         $reflection->setAccessible( true );
     184        if ( PHP_VERSION_ID < 80100 ) {
     185            $reflection->setAccessible( true );
     186        }
    177187
    178188        $this->assertSame( $expected, $reflection->invoke( null, $value, $unit ) );
Note: See TracChangeset for help on using the changeset viewer.