Skip to content

[Console] Choice values can also be objects #14229

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

Merged
merged 1 commit into from
Sep 14, 2020
Merged
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
5 changes: 5 additions & 0 deletions components/console/helpers/questionhelper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ from a predefined list::
$helper = $this->getHelper('question');
$question = new ChoiceQuestion(
'Please select your favorite color (defaults to red)',
// choices can also be PHP objects that implement __toString() method
['red', 'blue', 'yellow'],
0
);
Expand All @@ -116,6 +117,10 @@ from a predefined list::
// ... do something with the color
}

.. versionadded:: 5.2

Support for using PHP objects as choice values was introduced in Symfony 5.2.

The option which should be selected by default is provided with the third
argument of the constructor. The default is ``null``, which means that no
option is the default one.
Expand Down