Make WordPress Core


Ignore:
Timestamp:
09/11/2025 02:45:56 PM (6 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/error-protection/wpRecoveryModeCookieService.php

    r51650 r60729  
    3636        $service    = new WP_Recovery_Mode_Cookie_Service();
    3737        $reflection = new ReflectionMethod( $service, 'recovery_mode_hash' );
    38         $reflection->setAccessible( true );
     38        if ( PHP_VERSION_ID < 80100 ) {
     39            $reflection->setAccessible( true );
     40        }
    3941
    4042        $to_sign = sprintf( 'recovery_mode|%s|%s', time() - WEEK_IN_SECONDS - 30, wp_generate_password( 20, false ) );
     
    5557        $service    = new WP_Recovery_Mode_Cookie_Service();
    5658        $reflection = new ReflectionMethod( $service, 'generate_cookie' );
    57         $reflection->setAccessible( true );
     59        if ( PHP_VERSION_ID < 80100 ) {
     60            $reflection->setAccessible( true );
     61        }
    5862
    5963        $cookie  = $reflection->invoke( $service );
     
    7377        $service    = new WP_Recovery_Mode_Cookie_Service();
    7478        $reflection = new ReflectionMethod( $service, 'recovery_mode_hash' );
    75         $reflection->setAccessible( true );
     79        if ( PHP_VERSION_ID < 80100 ) {
     80            $reflection->setAccessible( true );
     81        }
    7682
    7783        $to_sign = sprintf( 'recovery_mode|%s|%s', 'month', wp_generate_password( 20, false ) );
     
    9399        $service    = new WP_Recovery_Mode_Cookie_Service();
    94100        $reflection = new ReflectionMethod( $service, 'generate_cookie' );
    95         $reflection->setAccessible( true );
     101        if ( PHP_VERSION_ID < 80100 ) {
     102            $reflection->setAccessible( true );
     103        }
    96104
    97105        $this->assertTrue( $service->validate_cookie( $reflection->invoke( $service ) ) );
Note: See TracChangeset for help on using the changeset viewer.