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/theme/wpThemeGetBlockPatterns.php

    r58025 r60729  
    4949    private function get_pattern_cache( $wp_theme ) {
    5050        $reflection = new ReflectionMethod( $wp_theme, 'get_pattern_cache' );
    51         $reflection->setAccessible( true );
     51        if ( PHP_VERSION_ID < 80100 ) {
     52            $reflection->setAccessible( true );
     53        }
    5254
    5355        $pattern_cache = $reflection->invoke( $wp_theme, 'get_pattern_cache' );
    54         $reflection->setAccessible( false );
     56        if ( PHP_VERSION_ID < 80100 ) {
     57            $reflection->setAccessible( false );
     58        }
    5559
    5660        return $pattern_cache;
     
    6569    private function get_cache_hash( $wp_theme ) {
    6670        $reflection = new ReflectionProperty( get_class( $wp_theme ), 'cache_hash' );
    67         $reflection->setAccessible( true );
     71        if ( PHP_VERSION_ID < 80100 ) {
     72            $reflection->setAccessible( true );
     73        }
    6874        $cache_hash = $reflection->getValue( $wp_theme );
    69         $reflection->setAccessible( false );
     75        if ( PHP_VERSION_ID < 80100 ) {
     76            $reflection->setAccessible( false );
     77        }
    7078        return $cache_hash;
    7179    }
Note: See TracChangeset for help on using the changeset viewer.