Skip to content

Commit

Permalink
bug #34114 [Console] SymonfyStyle - Check value isset to avoid PHP no…
Browse files Browse the repository at this point in the history
…tice (leevigraham)

This PR was merged into the 3.4 branch.

Discussion
----------

[Console] SymonfyStyle - Check value isset to avoid PHP notice

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34093
| License       | MIT
| Doc PR        | n/a

This PR addresses the issue when a default value is not a valid choice. Currently this would throw a notice which outputs to the console.

This fix is a similar implementation to the `QuestionHelper`: https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/Console/Helper/QuestionHelper.php#L63

Example console command and output can be found in the issue: #34093

Commits
-------

c9072c7 Check value isset to avoid PHP notice
  • Loading branch information
fabpot committed Feb 3, 2020
2 parents 78641e0 + c9072c7 commit a536342
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Style/SymfonyStyle.php
Expand Up @@ -229,7 +229,7 @@ public function choice($question, array $choices, $default = null)
{
if (null !== $default) {
$values = array_flip($choices);
$default = $values[$default];
$default = isset($values[$default]) ? $values[$default] : $default;
}

return $this->askQuestion(new ChoiceQuestion($question, $choices, $default));
Expand Down

0 comments on commit a536342

Please sign in to comment.