Make WordPress Core

Opened 3 months ago

Closed 3 months ago

Last modified 2 months ago

#63956 closed defect (bug) (fixed)

PHP 8.5: `setAccessible` deprecations

Reported by: swissspidy's profile swissspidy Owned by: swissspidy's profile swissspidy
Milestone: 6.9 Priority: normal
Severity: normal Version:
Component: General Keywords: php85 has-patch has-unit-tests
Focuses: tests, php-compatibility Cc:

Description (last modified by swissspidy)

Parent ticket for all things PHP 8.5: #63061


ReflectionProperty::setAccessible() and similar are deprecated since 8.5, as they have no effect since 8.1. See https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_reflectionsetaccessible

The solution is to call these functions only conditionally (e.g. if (\PHP_VERSION_ID < 80100) { $reflection->setAccessible(true); })

There are quite a few instances in core tests that we need to fix. See https://github.com/search?q=repo%3AWordPress%2Fwordpress-develop+setAccessible+language%3APHP&type=code&l=PHP

Change History (7)

#1 @swissspidy
3 months ago

  • Description modified (diff)

#2 @swissspidy
3 months ago

  • Milestone changed from Awaiting Review to 6.9

#3 @rishabhwp
3 months ago

I’d be happy to work on this and will submit a PR soon.

This ticket was mentioned in PR #9847 on WordPress/wordpress-develop by @rishabhwp.


3 months ago
#4

  • Keywords has-patch has-unit-tests added; needs-patch removed

#5 @swissspidy
3 months ago

  • Owner set to swissspidy
  • Resolution set to fixed
  • Status changed from new to closed

In 60729:

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.

#6 @swissspidy
3 months ago

In 60731:

Code Modernization: Fix setAccessible() PHP version comparison in two instances.

Follow-up to [60729].

See #63956.

#7 @swissspidy
2 months ago

In 60903:

Privacy: Wrap Reflection*::setAccessible() call in conditional check.

These methods are no-ops since PHP 8.1 and deprecated since PHP 8.5.

Reference: PHP RFC: Deprecations for PHP 8.5: Deprecate `Reflection*::setAccessible()`.

See #63956, #44267.

Note: See TracTickets for help on using tickets.