Thanks to visit codestin.com
Credit goes to github.com

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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/Symfony/Component/Console/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

{
throw new LogicException('You must override the execute() method in the concrete command class.');
}
Expand Down Expand Up @@ -256,10 +256,6 @@ public function run(InputInterface $input, OutputInterface $output)
$statusCode = ($this->code)($input, $output);
} else {
$statusCode = $this->execute($input, $output);

if (!\is_int($statusCode)) {
throw new \TypeError(sprintf('Return value of "%s::execute()" must be of the type int, "%s" returned.', static::class, get_debug_type($statusCode)));
}
}

return is_numeric($statusCode) ? (int) $statusCode : 0;
Expand Down