Skip to content

[Console] Add the typehint on Command class, to be coherent with BC Break on 4.4 #39182

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

Closed
wants to merge 1 commit into from

Conversation

Taluu
Copy link
Contributor

@Taluu Taluu commented Nov 26, 2020

Q A
Branch? 5.1
Bug fix? no (not really)
New feature? no
Deprecations? no
Tickets ~
License MIT
Doc PR ~

There was a deprecation on 4.4, stating that the execute method should only return an int (0 for success). It wasn't applied on 5.1, so here goes.

I also removed the TypeError if the execute method doesn't return an int, as php should do the job if the typehint is not set.

@Taluu Taluu requested a review from chalasr as a code owner November 26, 2020 16:54
@carsonbot carsonbot added this to the 5.1 milestone Nov 26, 2020
@@ -159,7 +159,7 @@ protected function configure()
*
* @see setCode()
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
Copy link
Member

Choose a reason for hiding this comment

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

This is a BC break. We cannot do this before Symfony 6.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, but as I said, it was already deprecated in 4.4 : see #33775

I think it was forgotten when the switch was made.

Copy link
Member

Choose a reason for hiding this comment

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

it was deprecated to return null indeed. And that's indeed forbidden in 5.1.0. But it is perfectly valid to write code in 5.1.0 which always return an int but without the return type. and that's where the BC break is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough. I'll wait to propose this for 6 then (if I didn't forgot 😂 ).

Copy link
Member

Choose a reason for hiding this comment

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

we won't because there are many methods that will benefit from a similar change and are waiting for v6

@carsonbot carsonbot changed the title Add the typehint on Command class, to be coherent with BC Break on 4.4 [Console] Add the typehint on Command class, to be coherent with BC Break on 4.4 Nov 26, 2020
@stof
Copy link
Member

stof commented Nov 26, 2020

The issue is that this is technically a BC break, as it is possible to write code on 5.1.0 without the typehint applied (and child classes are allowed to restrict the return type, but not to widen it).

@Taluu
Copy link
Contributor Author

Taluu commented Nov 26, 2020

Yep, but as it was already mentionned and documented on 4.4, shouldn't it be fine ? Otherwise this is just pendantics IMO and can wait for 6

@Taluu Taluu closed this Nov 26, 2020
@Taluu Taluu deleted the console/typehint branch November 26, 2020 17:10
@Wirone
Copy link
Contributor

Wirone commented Aug 18, 2022

I am wondering why it wasn't done in 5.0 in the first place, since it was deprecated in 4.4 and it was perfect moment for changing signature 🤔 But as far as I see it wasn't added in 6.* too... 🙄

@stof
Copy link
Member

stof commented Aug 18, 2022

This was not done in 5.0, because adding native return types in a way allowing to support multiple versions of Symfony requires the variance rules added in PHP 7.2, and Symfony 4.4 was supporting PHP 7.1 (meaning that it was not possible to write code working on PHP 7.1 and Symfony 4.4 that was also supporting the return type added in 5.0 if we were adding it).
Then, when doing 6.0, we excluded a few return types that were more painful to support for the ecosystem due to having their own non-final classes needing to be updated first in a major version of their own package. Those places (tracked in the Symfony code base) will be typed in Symfony 7.0 (as those projects will have had 2 more years to do such a major version bump).

@Wirone
Copy link
Contributor

Wirone commented Aug 18, 2022

Thanks @stof for the info. I suppose you're talking about external packages having "symfony/console": "^4 | ^5" in their dependencies? It's not so obvious that adding such return type would break something, so I appreciate it was addressed properly 🙂

I imagine this would be edge case requiring at least 3 levels of dependency: project requiring package, that requires Symfony with multiple versions supported, am I right? So intermediate package does not decide about PHP version where it's used and about Symfony version resolved. In this case, having return type in Symfony v5 would block interim packages from supporting multiple versions of Symfony and in the end those would need to drop support of some PHP versions. Correct me if I'm wrong, I'm just thinking out loud because I want to understand it properly 🙂

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.

6 participants