Make WordPress Core


Ignore:
Timestamp:
09/11/2025 02:45:56 PM (13 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/wpThemeJsonResolver.php

    r60234 r60729  
    7878
    7979                static::$property_blocks_cache = new ReflectionProperty( WP_Theme_JSON_Resolver::class, 'blocks_cache' );
    80                 static::$property_blocks_cache->setAccessible( true );
     80                if ( PHP_VERSION_ID < 80100 ) {
     81                        static::$property_blocks_cache->setAccessible( true );
     82                }
    8183                static::$property_blocks_cache_orig_value = static::$property_blocks_cache->getValue();
    8284
    8385                static::$property_core = new ReflectionProperty( WP_Theme_JSON_Resolver::class, 'core' );
    84                 static::$property_core->setAccessible( true );
     86                if ( PHP_VERSION_ID < 80100 ) {
     87                        static::$property_core->setAccessible( true );
     88                }
    8589                static::$property_core_orig_value = static::$property_core->getValue();
    8690        }
    … …  
    307311        public function test_has_same_registered_blocks_when_all_blocks_not_cached( $origin, array $cache = array() ) {
    308312                $has_same_registered_blocks = new ReflectionMethod( WP_Theme_JSON_Resolver::class, 'has_same_registered_blocks' );
    309                 $has_same_registered_blocks->setAccessible( true );
     313                if ( PHP_VERSION_ID < 80100 ) {
     314                        $has_same_registered_blocks->setAccessible( true );
     315                }
    310316                $expected_cache = $this->get_registered_block_names();
    311317
    … …  
    381387        public function test_has_same_registered_blocks_when_all_blocks_are_cached( $origin ) {
    382388                $has_same_registered_blocks = new ReflectionMethod( WP_Theme_JSON_Resolver::class, 'has_same_registered_blocks' );
    383                 $has_same_registered_blocks->setAccessible( true );
     389                if ( PHP_VERSION_ID < 80100 ) {
     390                        $has_same_registered_blocks->setAccessible( true );
     391                }
    384392                $expected_cache = $this->get_registered_block_names();
    385393
    … …  
    837845                // Force-unset $i18n_schema property to "unload" translation schema.
    838846                $property = new ReflectionProperty( $theme_json_resolver, 'i18n_schema' );
    839                 $property->setAccessible( true );
     847                if ( PHP_VERSION_ID < 80100 ) {
     848                        $property->setAccessible( true );
     849                }
    840850                $property->setValue( null, null );
    841851
Note: See TracChangeset for help on using the changeset viewer.