Skip to content

[Console] Fix bug with $output overloading #16621

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 2 commits into from
Closed

Conversation

wouterj
Copy link
Member

@wouterj wouterj commented Nov 21, 2015

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets https://github.com/symfony/symfony-standard/issues/887, #16622
License MIT
Doc PR -

This is exactly why variable overloading isn't a great idea :)

@javiereguiluz
Copy link
Member

@wouterj I agree! that's why I asked for help ... but sadly the issue stalled: #16000

@wouterj
Copy link
Member Author

wouterj commented Nov 21, 2015

Btw, not sure where the error is coming from as SymfonyStyle implements OutputInterface and the isDebug method, but this is at least more correct than before.

@intermike
Copy link

Awesome. This fix works for me. No error so far.

Should I close the issue 16622 by myself?

@wouterj
Copy link
Member Author

wouterj commented Nov 21, 2015

@intermike good to hear that :) I've added your issue to the PR table in the description. When this PR is merged, the issue will be closed automatically.

Thanks for reporting this to Symfony!

@@ -72,9 +72,9 @@ protected function configure()
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $cliOutput)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not named according to the parent definition. Also inheritdoc will not work this way.

Copy link
Member

Choose a reason for hiding this comment

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

Yea, and it makes more sense to me to do the opposite: use OutputInterface $output here, then rename the other variable, like $styleOutput = new SymfonyStyle(...). That's mostly because we tend to always call the argument $output.

Copy link
Member

Choose a reason for hiding this comment

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

@weaverryan do you have some ideas for #16000? Thanks!

@ogizanagi
Copy link
Contributor

Btw, not sure where the error is coming from as SymfonyStyle implements OutputInterface and the isDebug method, but this is at least more correct than before.

@wouterj : It only does in 3.0, not in 2.8 actually. Because it's only part of the OutputInterface since 3.0 for BC reasons, and the implementation in 2.8 was done in the Output class. Which is not extended by the SymfonyStyle nor OutputStyle.
IMO it won't be a shame for the OutputStyle to provide those methods as done in 3.0.

@wouterj
Copy link
Member Author

wouterj commented Nov 22, 2015

👍 to add them in 2.7. I consider it a bug that it isn't

@ogizanagi
Copy link
Contributor

It would be kind of ugly however, as it will require checking if each method exists in the provided $output, which could be any OutputInterface instance. Something like:

# OutputStyle.php

public function isDebug()
{
    if (!method_exists($this->output, 'isDebug')) {
        throw new \BadMethodCallException(sprintf(
            'Method "%s" of "%s" does not exist', 
            get_class($this->output), 
            __METHOD__
        ));
    }

    return $this->output->isDebug();
}

Also we wouldn't be able to base ourself on this API for solving this issue depending on the output instance used in the commands :/

@weaverryan
Copy link
Member

Status: Needs work

@wouterj
Copy link
Member Author

wouterj commented Nov 25, 2015

Changed it to set $cliOutput in the code instead of the parameter (proposal of @intermike). This way, the PR can be merged without deciding on the name of the Symfony style variable.

@@ -74,7 +74,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output = new SymfonyStyle($input, $output);
$output = new SymfonyStyle($input, $cliOutput = $output);
Copy link
Member

Choose a reason for hiding this comment

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

I don't really care, but this may not be super clear to people reading the code - maybe we can set it in its own line

@weaverryan
Copy link
Member

👍

The naming - and details in this PR - are all internal things anyways that can be changed later.

@fabpot
Copy link
Member

fabpot commented Nov 26, 2015

Thank you @wouterj.

@fabpot fabpot closed this Nov 26, 2015
fabpot added a commit that referenced this pull request Nov 26, 2015
This PR was squashed before being merged into the 2.8 branch (closes #16621).

Discussion
----------

[Console] Fix bug with $output overloading

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | https://github.com/symfony/symfony-standard/issues/887, #16622
| License       | MIT
| Doc PR        | -

This is exactly why variable overloading isn't a great idea :)

Commits
-------

5764a00 [Console] Fix bug with  overloading
@wouterj wouterj deleted the patch-19 branch November 26, 2015 17:03
This was referenced Nov 30, 2015
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.

8 participants