Skip to content

Conversation

@jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Aug 10, 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

Closes #12497

sbuerk added a commit to TYPO3/testing-framework that referenced this pull request Aug 16, 2025
Method ReflectionProperty::setAccessible() is deprecated since 8.5, as
it has no effect since PHP8.1. This change keeps the calls for earlier
PHP versions than 8.5 using a version check to ommit calls for PHP8.5.0
or higher.

[1] composer/composer#12493

Releases: 7
sbuerk added a commit to TYPO3/testing-framework that referenced this pull request Aug 16, 2025
Method ReflectionProperty::setAccessible() is deprecated since 8.5, as
it has no effect since PHP8.1. This change keeps the calls for earlier
PHP versions than 8.5 using a version check to ommit calls for PHP8.5.0
or higher.

[1] composer/composer#12493

Releases: 7
sbuerk added a commit to TYPO3/testing-framework that referenced this pull request Aug 18, 2025
Method ReflectionProperty::setAccessible() is deprecated since 8.5, as
it has no effect since PHP8.1. This change keeps the calls for earlier
PHP versions than 8.5 using a version check to ommit calls for PHP8.5.0
or higher.

[1] composer/composer#12493

Releases: 7
@jrfnl
Copy link
Contributor Author

jrfnl commented Aug 19, 2025

P.S.: let me know if you would like me to rebase this against 2.8.

@Seldaek Seldaek added this to the 2.8 milestone Aug 20, 2025
@Seldaek
Copy link
Member

Seldaek commented Aug 20, 2025

Yes please rebase on 2.8, but feel free to ignore phpstan errors I'll add these to the baseline myself (I got a script here due to our dual baseline mess).

if ($e instanceof TransportException) {
$reflProp = new \ReflectionProperty($e, 'code');
$reflProp->setAccessible(true);
(\PHP_VERSION_ID < 80100) && $reflProp->setAccessible(true);
Copy link
Contributor

@stof stof Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid the phpstan error about boolean in &&, use a if statement instead of using the boolean operator as a control flow operator (or use the and control flow operator, but this is not used in the Composer codebase AFAICT).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather keep && and put it in the baseline for now, that doesn't hurt, and it is code that will disappear eventually.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then use and which is the control flow operator (and won't report that error in phpstan)

Copy link
Contributor Author

@jrfnl jrfnl Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've actioned this in a separate commit as I suspect it may be flagged for code style (use of and often is).
@Seldaek If you want to keep the change, please squash-merge the commits as these really shouldn't be separate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then use and which is the control flow operator (and won't report that error in phpstan)

@stof Hmm ... looks like that's not true.... https://github.com/composer/composer/actions/runs/17103745891/job/48507066776

@Seldaek Let me know f you'd like me to remove the commit again.

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 force-pushed the feature/fix-setaccessible-deprecations-php-8.5 branch from d94c8a3 to d47e718 Compare August 20, 2025 15:58
@jrfnl jrfnl changed the base branch from main to 2.8 August 20, 2025 15:59
@jrfnl jrfnl force-pushed the feature/fix-setaccessible-deprecations-php-8.5 branch from d47e718 to 68756ce Compare August 20, 2025 15:59
@jrfnl
Copy link
Contributor Author

jrfnl commented Aug 20, 2025

Yes please rebase on 2.8, but feel free to ignore phpstan errors I'll add these to the baseline myself (I got a script here due to our dual baseline mess).

Done (and changed the "base" for the PR).

@jrfnl
Copy link
Contributor Author

jrfnl commented Aug 20, 2025

FYI: I've double-checked with a code-search that there were no calls to ->setAccessible() in the 2.8 branch which aren't in the main branch (and which may have been missed in the rebase).

@Seldaek
Copy link
Member

Seldaek commented Aug 20, 2025

Looks like and didn't really help but whatever :) Thanks!

@Seldaek Seldaek merged commit 465c3a3 into composer:2.8 Aug 20, 2025
18 of 20 checks passed
@jrfnl jrfnl deleted the feature/fix-setaccessible-deprecations-php-8.5 branch August 20, 2025 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants