From 62a71dc67c479625ea11c3767d117ef8e3460121 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sat, 12 Sep 2020 12:11:36 +0200 Subject: [PATCH] [Console] Choice values can also be objects --- components/console/helpers/questionhelper.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/console/helpers/questionhelper.rst b/components/console/helpers/questionhelper.rst index 89716c8d078..a4cc68b80b2 100644 --- a/components/console/helpers/questionhelper.rst +++ b/components/console/helpers/questionhelper.rst @@ -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 ); @@ -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.