-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
PHP 8.5 | Prevent deprecation notices for Reflection*::setAccessible() #12493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHP 8.5 | Prevent deprecation notices for Reflection*::setAccessible() #12493
Conversation
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
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
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
|
P.S.: let me know if you would like me to rebase this against 2.8. |
|
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). |
src/Composer/Console/Application.php
Outdated
| if ($e instanceof TransportException) { | ||
| $reflProp = new \ReflectionProperty($e, 'code'); | ||
| $reflProp->setAccessible(true); | ||
| (\PHP_VERSION_ID < 80100) && $reflProp->setAccessible(true); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then use
andwhich 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
d94c8a3 to
d47e718
Compare
d47e718 to
68756ce
Compare
Done (and changed the "base" for the PR). |
|
FYI: I've double-checked with a code-search that there were no calls to |
|
Looks like |
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, thesetAccessible()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