Skip to content

PHP 8.5 | Tests: prevent deprecation notice for Reflection*::setAccessible()#1850

Merged
wimg merged 1 commit intodevelopfrom
feature/fix-test-runtime-deprecations-php-8.5
Aug 13, 2025
Merged

PHP 8.5 | Tests: prevent deprecation notice for Reflection*::setAccessible()#1850
wimg merged 1 commit intodevelopfrom
feature/fix-test-runtime-deprecations-php-8.5

Conversation

@jrfnl
Copy link
Copy Markdown
Member

@jrfnl jrfnl commented Aug 9, 2025

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.

With the latter in mind, this commit prevents the deprecation notice by making the calls to setAccessible() conditional.

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

…sible()

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.

With the latter in mind, this commit prevents the deprecation notice by making the calls to `setAccessible()` conditional.

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
@jrfnl jrfnl added this to the 10.0.0 milestone Aug 9, 2025
@jrfnl jrfnl requested a review from wimg August 9, 2025 23:12
@jrfnl jrfnl added Type: chores/QA PR: quick merge PR only contains relatively simple changes PR: ready for review labels Aug 9, 2025
@jrfnl
Copy link
Copy Markdown
Member Author

jrfnl commented Aug 9, 2025

Note: I expect this won't fix all notices yet as we're also using TestUtils from PHPCSUtils. A PR to fix those is already open and a new release is expected soon.

@jrfnl
Copy link
Copy Markdown
Member Author

jrfnl commented Aug 9, 2025

Note: aside from the deprecation notices from PHPCSUtils, there is one actual test failure:

1) PHPCompatibility\Tests\TypeCasts\NewTypeCastsUnitTest::testNewTypeCasts with data set #1 ('The binary cast', '5.2.0', [9, 10, 11, 12, 16, 18], '5.3', '5.2')
Expected error 'The binary cast is not present in PHP version 5.2.0 or earlier' on line number 9, but none found.

This is due to a bug in the deprecation code in PHP Core itself. A fix for this has already been merged upstream and the build should pass again once the setup-php nightly image for PHP 8.5 has regenerated somewhere in the next 24 hours.

@wimg wimg merged commit 1ffbc77 into develop Aug 13, 2025
117 of 121 checks passed
@wimg wimg deleted the feature/fix-test-runtime-deprecations-php-8.5 branch August 13, 2025 19:03
@github-actions github-actions bot removed PR: quick merge PR only contains relatively simple changes PR: ready for review labels Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants