-
-
Notifications
You must be signed in to change notification settings - Fork 431
[Php85] Remove calls to deprecated no-op functions #7128
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
[Php85] Remove calls to deprecated no-op functions #7128
Conversation
|
On php <8.4, is that function necessary? If needed, then downgrade rule need to exists first, or make a rule to change code like: - finfo_close($info);
+if (PHP_VERSION_ID < 80500) {
+ finfo_close($info);
+} |
|
@samsonasik According to the RFC, all of them have been no-ops at least since PHP 8.1, see listing at https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_no-op_functions_from_the_resource_to_object_conversion PS: I will fix merge conflicts tomorrow as all of the PHP 8.5 PRs change php85.php. |
|
I prefer to have code that less bc break even downgraded to php 7 on our downgrade rule: https://github.com/rectorphp/rector-downgrade-php so if there is no downgrade rule, imo, the code should have backward compatible code. |
|
I am not familiar with the downgrade package but wouldn't most people applying this rule or the PHP 8.5 rule set want to stay on PHP 8.5+, so that such an additional condition would be useless in this case and would just add more code instead of removing the "useless" code. Can you point me to existing examples in the Rector source code for such a scenario that I came have a look at? 🙂 |
|
rector-src itself shipped as php 7.4 compatible code, include the prefixed "vendor" https://github.com/rectorphp/rector/tree/main/vendor which if the code exists, and rector for example require php 8.5, and the code removed, this should have flag handling to cover that, except, the list of function doesn't have any functionality in previous versions. If there is no way to do that, possibly can be an optional list collection of rules. |
|
Agree we should rewrite it to a PHP_VERSION based check. A separate rector rule can remove |
|
Can you provide me with an existing code example where an expression (FuncCall) is replaced with a statement to see how to properly do that? |
|
e.g. |
667be58 to
e1f46f3
Compare
|
I opted for a reusable rector rule that wraps certain function calls in a To keep it simple for now, it only considers expressions with only the function call, not in assignments and conditions, for example. But then, three functions, Do you think that these cases should also be considered with a return type expectation of |
rules/DeadCode/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector.php
Outdated
Show resolved
Hide resolved
|
a similar rector (separate PR) would be usefull for |
...ncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/skip_func_call_in_condition.php.inc
Show resolved
Hide resolved
|
@staabm Actually, I wanted to do that but then thought that the deprecation of these methods where voted against but I confused that with the I will have look at that later once this PR is through. |
rules/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector.php
Outdated
Show resolved
Hide resolved
|
It seems if this rule is combined with withRules([
RemovePhpVersionIdCheckRector::class,
])
->withConfiguredRule(WrapFuncCallWithPhpVersionIdCheckerRector::classs, [
new WrapFuncCallWithPhpVersionIdChecker('curl_close', 80500),
]);so probably something to consider is check what existig rules registered to avoid repetive flip flop on repetitive run. |
152e7ee to
50b18ce
Compare
rules/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector.php
Outdated
Show resolved
Hide resolved
|
@samsonasik Done. Can you please mark the appropriate discussions are solved to avoid to many multiple "open" discusssions? (I will rebase again due to merge conflicts.) |
|
yes, marked as resolved 👍 |
d81dc8a to
8b653cd
Compare
samsonasik
left a comment
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.
Looks good to me 👍
|
Thank you @mttsch |
|
I'm going through some failing tests in unrelated feature, and just got to this rule. Correct me if I'm wrong. Rector should focus on deprecation that have a replacement, not just wrap everything deprecated with ifs. That does not bring value and silently creates BC breaks instead. PHPStan is with https://github.com/phpstan/phpstan-deprecation-rules is here for that and require human touch. |
|
@TomasVotruba the issue without wrapping is, when code downgraded, there is no replacement for removed code, so to keep both upgrade and downgrade work, the wrap if is needed. For example: curl_exec();
curl_close();On PHP 8.5, |
|
and the deprecation notice cause unwanted behaviour for user that see the notice in the application, and may be removed in future php 8.6 or php 9, so to keep works on both upgrade and downgrade, the wrap is needed. |
|
@samsonasik I see. In that case we should wait till these functions are actually removed. I'd be surprised to upgrade to PHP 8.5 and suddently have more lines in my project around deprecated functions. Are there any such functions in Rector downgraded codebase? |
|
Yes, we use the wrap on purpose, for example, the without the wrap, when code read by php 8.5 that The purpose is, when code downgraded, it works, read by greater Php version, it keep works, the use case is on rector code itself when run php 8.5 |
|
In downgrade it makes sense, but upgrade path should be independent and not clutter codebase. Think of them as 2 processes that have no idea about each other. Code I write in PHP 8.5 should work on downgrade, regardless if it was upgraded with Rector or not. |
|
Are there any such functions in Rector downgraded codebase? |
|
Yes, these are dev, one of them even should not be part of the released package. We don't do any curl_ calls. |
|
I'll replace it with func call removal. |
|
Ref #7520 |

No description provided.