Make WordPress Core

Opened 13 months ago

Closed 13 months ago

Last modified 12 months ago

#63956 closed defect (bug) (fixed)

PHP 8.5: `setAccessible` deprecations

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

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
13 months ago

  • Description modified (diff)

#2 @swissspidy
13 months ago

  • Milestone Awaiting Review → 6.9

#3 @rishabhwp
13 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.


13 months ago
#4

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

#5 @swissspidy
13 months ago

  • Owner set to swissspidy
  • Resolution → fixed
  • Status new → 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
13 months ago

In 60731:

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

Follow-up to [60729].

See #63956.

#7 @swissspidy
12 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.