Make WordPress Core


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

    r58176 r60729  
    663663        $reflection = new ReflectionClass( $registry );
    664664        $property   = $reflection->getProperty( 'registered_patterns' );
    665         $property->setAccessible( true );
     665        if ( PHP_VERSION_ID < 80100 ) {
     666            $property->setAccessible( true );
     667        }
    666668
    667669        // Get the value of the private property.
    668670        $registered_patterns = $property->getValue( $registry );
    669         $property->setAccessible( false );
     671        if ( PHP_VERSION_ID < 80100 ) {
     672            $property->setAccessible( false );
     673        }
    670674
    671675        return $registered_patterns;
     
    682686        $reflection = new ReflectionClass( $registry );
    683687        $property   = $reflection->getProperty( 'registered_patterns' );
    684         $property->setAccessible( true );
     688        if ( PHP_VERSION_ID < 80100 ) {
     689            $property->setAccessible( true );
     690        }
    685691
    686692        // Set the value of the private property.
    687693        $property->setValue( $registry, $value );
    688         $property->setAccessible( false );
     694        if ( PHP_VERSION_ID < 80100 ) {
     695            $property->setAccessible( false );
     696        }
    689697    }
    690698}
Note: See TracChangeset for help on using the changeset viewer.