Make WordPress Core


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

    r59979 r60729  
    103103
    104104        $reflection = new ReflectionMethod( $query1, 'generate_cache_key' );
    105         $reflection->setAccessible( true );
     105        if ( PHP_VERSION_ID < 80100 ) {
     106            $reflection->setAccessible( true );
     107        }
    106108
    107109        $cache_key_1 = $reflection->invoke( $query1, $query_vars, $request );
     
    159161
    160162        $reflection = new ReflectionMethod( $query1, 'generate_cache_key' );
    161         $reflection->setAccessible( true );
     163        if ( PHP_VERSION_ID < 80100 ) {
     164            $reflection->setAccessible( true );
     165        }
    162166
    163167        $cache_key_1 = $reflection->invoke( $query1, $query_vars, $request );
     
    192196
    193197        $reflection = new ReflectionMethod( $query1, 'generate_cache_key' );
    194         $reflection->setAccessible( true );
     198        if ( PHP_VERSION_ID < 80100 ) {
     199            $reflection->setAccessible( true );
     200        }
    195201
    196202        $cache_key_1 = $reflection->invoke( $query1, $query_vars, $request1 );
     
    228234
    229235        $reflection_q1 = new ReflectionProperty( $query1, 'query_cache_key' );
    230         $reflection_q1->setAccessible( true );
     236        if ( PHP_VERSION_ID < 80100 ) {
     237            $reflection_q1->setAccessible( true );
     238        }
    231239
    232240        $reflection_q2 = new ReflectionProperty( $query2, 'query_cache_key' );
    233         $reflection_q2->setAccessible( true );
     241        if ( PHP_VERSION_ID < 80100 ) {
     242            $reflection_q2->setAccessible( true );
     243        }
    234244
    235245        $this->assertNotSame( $request1, $request2, 'Queries should not match' );
     
    289299
    290300        $reflection_q1 = new ReflectionProperty( $query1, 'query_cache_key' );
    291         $reflection_q1->setAccessible( true );
     301        if ( PHP_VERSION_ID < 80100 ) {
     302            $reflection_q1->setAccessible( true );
     303        }
    292304
    293305        $reflection_q2 = new ReflectionProperty( $query2, 'query_cache_key' );
    294         $reflection_q2->setAccessible( true );
     306        if ( PHP_VERSION_ID < 80100 ) {
     307            $reflection_q2->setAccessible( true );
     308        }
    295309
    296310        $this->assertNotSame( $request1, $request2, 'Queries should not match' );
     
    346360
    347361        $reflection_q1 = new ReflectionProperty( $query1, 'query_cache_key' );
    348         $reflection_q1->setAccessible( true );
     362        if ( PHP_VERSION_ID < 80100 ) {
     363            $reflection_q1->setAccessible( true );
     364        }
    349365
    350366        $reflection_q2 = new ReflectionProperty( $query2, 'query_cache_key' );
    351         $reflection_q2->setAccessible( true );
     367        if ( PHP_VERSION_ID < 80100 ) {
     368            $reflection_q2->setAccessible( true );
     369        }
    352370
    353371        $this->assertNotSame( $request1, $request2, 'Queries should not match' );
     
    386404
    387405        $reflection_q1 = new ReflectionProperty( $query1, 'query_cache_key' );
    388         $reflection_q1->setAccessible( true );
     406        if ( PHP_VERSION_ID < 80100 ) {
     407            $reflection_q1->setAccessible( true );
     408        }
    389409
    390410        $reflection_q2 = new ReflectionProperty( $query2, 'query_cache_key' );
    391         $reflection_q2->setAccessible( true );
     411        if ( PHP_VERSION_ID < 80100 ) {
     412            $reflection_q2->setAccessible( true );
     413        }
    392414
    393415        $this->assertSame( $request1, $request2, 'Queries should match' );
Note: See TracChangeset for help on using the changeset viewer.