-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Command::execute() should always return int - deprecate returning null #33747
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
Comments
I think that's a good idea. Why not add a return type in 5.0 so that a TypeError would be thrown? 🤔 |
So we basically need to do the following:Tasks in 4.4 First of all we need to introduce a deprecation message for nullable or non-int return values of
After that we can adjust the core commands with exchanging I checked all Bundles and Bridges which provide Commands:
Tasks in 5.0
|
…DebugCommand (jschaedl) This PR was merged into the 3.4 branch. Discussion ---------- [FrameworkBundle] Fix wrong returned status code in ConfigDebugCommand | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #33747<!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | - This is a follow-up PR caused by #33775 (comment) Commits ------- 9b5ced2 [FrameworkBundle] Fix wrong returned status code in ConfigDebugCommand
…de (jschaedl) This PR was merged into the 4.4 branch. Discussion ---------- [Console] Add deprecation message for non-int statusCode | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | yes <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #33747 <!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | - ### What was done: - [x] added deprecation message for non-int return value in Command::execute() - [x] fixed all core commands to return proper int values - [x] added proper return type-hint to Command::execute() method in all core Commands Commits ------- 98c4f6a [Console] Command::execute() should always return int - deprecate returning null
…ling Command::execute() (jschaedl) This PR was merged into the 5.0-dev branch. Discussion ---------- [Console] Throw a TypeError for non-int return value calling Command::execute() | Q | A | ------------- | --- | Branch? | 5.0 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | yes <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #33747 <!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | - <!-- required for new features --> ### Todo - [x] needs to be rebased after 4.4 was merged into master (see: #33805) Commits ------- b3a3b0c [Console] Throw a TypeError for non-int return values on calling Command::execute()
…bus) This PR was merged into the 2.15 branch. Discussion ---------- Command::execute() should always return an integer In Symfony 4.4, a deprecation error is triggered if `Command::execute()` does not return an integer, see symfony/symfony#33747. This PR adds the necessary `return` statements. Commits ------- ee758b1 Command::execute() should always return an integer.
I realize its too late but the PR doesn't give any reasoning as to why this change is helpful. It does break a large number of projects (or anyway it broke all of mine) and it makes the code fairly ugly with the lone |
Per symfony/symfony#33747, required for Symfony 5.0 upgrade.
I don't get this restriction. Even in a strictly typed language like C I can have an int function that returns nothing, it will be automatically converted to 0. Also you can define main as being void. So why C is more flexible than Symfony here? |
According to: https://symfony.com/doc/current/contributing/community/releases.html
But 4.4 this is now throwing an exception, and broke all of my commands? Why is this forced in 4.4 and not 5.0? This is the second thing now that Symfony have broke stuff in a minor version..... |
Can you be a bit more precise how this broke your application? |
It changes the execute method's signature and that constitutes a breaking change.
It will throw a notice AND break phpstan.
You're forcing this on every developer using symfony commands. I feel the question alone shows little empathy for the developers hit by this change. |
The method signature of the |
So you can see in 4.4 the So many of my scripts (near 100 of them) all started throwing "Return value of X::execute() should always be of type int since Symfony 4.4". The only fix was for me to go in and update all of them, thankfully it's quite an easy fix since I can just shove Example |
This looks like an issue with your setup if silenced deprecations are turned into errors. |
If feel strongly that my setup should not be dictatored by libraries used. See my comment about phpstan. It does also break the CI build process due to https://github.com/symfony/console/blob/4.4/Command/Command.php#L153. That being said, the PR also does not provide any reason for doing so in 4.4. |
Symfony is using this way to trigger deprecations since at least 2.8. If your error handler doesn't respect the silenced errors that is indeed something we cannot fix in the core.
We always deprecate things in a minor release (4.4 here) before removing it in the next major version (5.0 here) to provide a smooth upgrade path. |
By default
It seems that your error handler decides to ignore the intention behind the operator. Symfony does not "dictate" how you do things, but if you change rightfully expected behavior, you are responsible for the consequences. |
So because I have a try/catch it becomes BC??? That is extremely janky, libraries should expect people to have error handling... I have no custom error handling other than a try/catch, the rest is pure symfony, an example can be followed here: https://github.com/xivapi/xivapi.com/blob/master/src/Command/GameData/SaintCoinachRedisCommand.php |
Your error handler defined on line 75 of that exact class does not respect silenced errors. |
You may want to update it like this: set_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) {
if (0 === error_reporting()) {
return;
}
# print_r($errcontext);
throw new \Exception("{$errfile} {$errline} - {$errstr}", 0);
}); |
Thanks @xabbuh i had wrongly assumed because it forced throwing exceptions which were catch later on it would be fine, reading your post I see it removes the silence, so this is my mistake, really sorry |
I am glad we were able to resolve your issue. :) |
I think a |
Right now,
Command::execute()
returnsint|void
.I'd suggest we should deprecate returning void (or null) by throwing a deprecation when the method returns a non-int, in
Application
.We would need to update all core commands to
return 0;
where theyreturn;
right now.And in 5.0, we would make returning a non-int throw an exception, in preparation for adding a real return type in 6.0.
Help wanted.
The text was updated successfully, but these errors were encountered: