Skip to content

Commit e7c1f7c

Browse files
authored
Fix PHP 8.5 deprecations
Since PHP 8.1, calling the Reflection*::setAccessible() methods is no longer necessary as reflected properties/methods/etc will always be accessible. However, the method calls are still needed for PHP < 8.1. As of PHP 8.5, calling the Reflection*::setAccessible() methods is now formally deprecated and will yield a deprecation notice, which will fail test runs. As of PHP 9.0, the setAccessible() method(s) will be removed. Silencing the deprecation would mean, this would need to be "fixed" again come PHP 9.0, while the current solution should be stable, including for PHP 9.0. Ref: https://wiki.php.net/rfc/deprecations_php_8_5#extreflection_deprecations Fixes #1025
1 parent a846dee commit e7c1f7c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

classes/Collector_Assets.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,13 @@ protected static function get_script_modules(): ?array {
283283
$reflector = new ReflectionClass( $modules );
284284

285285
$get_marked_for_enqueue = $reflector->getMethod( 'get_marked_for_enqueue' );
286-
$get_marked_for_enqueue->setAccessible( true );
286+
(\PHP_VERSION_ID < 80100) and $get_marked_for_enqueue->setAccessible( true );
287287

288288
$get_dependencies = $reflector->getMethod( 'get_dependencies' );
289-
$get_dependencies->setAccessible( true );
289+
(\PHP_VERSION_ID < 80100) and $get_dependencies->setAccessible( true );
290290

291291
$get_src = $reflector->getMethod( 'get_src' );
292-
$get_src->setAccessible( true );
292+
(\PHP_VERSION_ID < 80100) and $get_src->setAccessible( true );
293293

294294
/**
295295
* @var array<string, array<string, mixed>> $enqueued
@@ -365,9 +365,9 @@ protected static function get_script_modules(): ?array {
365365
}
366366

367367
// @todo check isPrivate before changing visibility back
368-
$get_marked_for_enqueue->setAccessible( false );
369-
$get_dependencies->setAccessible( false );
370-
$get_src->setAccessible( false );
368+
(\PHP_VERSION_ID < 80100) and $get_marked_for_enqueue->setAccessible( false );
369+
(\PHP_VERSION_ID < 80100) and $get_dependencies->setAccessible( false );
370+
(\PHP_VERSION_ID < 80100) and $get_src->setAccessible( false );
371371

372372
return $sources;
373373
}

0 commit comments

Comments
 (0)