From 66f5cc968a2013ae97b695d5ab393f2fb0261692 Mon Sep 17 00:00:00 2001 From: Issam KHADIRI Date: Sun, 12 Jun 2022 17:57:21 +0200 Subject: [PATCH] Update questionhelper.rst hello, when running the example as it is, a deprecation message is shown (i'm on PHP 8.1.6). the deprecation message says that ``trim(): Passing null to parameter #1 ($string) of type string is deprecated``. what if we add a normalizer that returns an empty string when the entered value is `null` otherwise returns the user's intial input. with this suggestion, the example works great --- components/console/helpers/questionhelper.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/console/helpers/questionhelper.rst b/components/console/helpers/questionhelper.rst index d5ddf83a2e3..9159f66f652 100644 --- a/components/console/helpers/questionhelper.rst +++ b/components/console/helpers/questionhelper.rst @@ -420,6 +420,9 @@ You can also use a validator with a hidden question:: $helper = $this->getHelper('question'); $question = new Question('Please enter your password'); + $question->setNormalizer(function ($value) { + return null === $value ? '' : $value; + }); $question->setValidator(function ($value) { if (trim($value) == '') { throw new \Exception('The password cannot be empty');