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/wpTheme.php

    r60500 r60729  
    302302        $reflection          = new ReflectionClass( $theme );
    303303        $reflection_property = $reflection->getProperty( 'block_theme' );
    304         $reflection_property->setAccessible( true );
     304        if ( PHP_VERSION_ID < 80100 ) {
     305            $reflection_property->setAccessible( true );
     306        }
    305307
    306308        $this->assertSame( $expected, $reflection_property->getValue( $theme ) );
     
    612614        $theme           = new WP_Theme( 'twentytwentytwo', $this->theme_root );
    613615        $sanitize_header = new ReflectionMethod( $theme, 'sanitize_header' );
    614         $sanitize_header->setAccessible( true );
     616        if ( PHP_VERSION_ID < 80100 ) {
     617            $sanitize_header->setAccessible( true );
     618        }
    615619
    616620        $actual = $sanitize_header->invoke( $theme, 'UpdateURI', '<?php?><a href="http://example.org">http://example.org</a>' );
Note: See TracChangeset for help on using the changeset viewer.