Make WordPress Core


Ignore:
Timestamp:
09/11/2025 02:45:56 PM (14 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/script-modules/wpScriptModules.php

    r60704 r60729  
    876876        public function test_get_src() {
    877877                $get_src = new ReflectionMethod( $this->script_modules, 'get_src' );
    878                 $get_src->setAccessible( true );
     878                if ( PHP_VERSION_ID < 80100 ) {
     879                        $get_src->setAccessible( true );
     880                }
    879881
    880882                $this->script_modules->register(
    … …  
    13511353                $reflection_class    = new ReflectionClass( $script_modules );
    13521354                $registered_property = $reflection_class->getProperty( 'registered' );
    1353                 $registered_property->setAccessible( true );
     1355                if ( PHP_VERSION_ID < 80100 ) {
     1356                        $registered_property->setAccessible( true );
     1357                }
    13541358                return $registered_property->getValue( $script_modules );
    13551359        }
Note: See TracChangeset for help on using the changeset viewer.