From bf9e245ea55ed3b0565dc5e58393265ff8374287 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 d6cdb7c67ab..664f1b0d1df 100644 --- a/components/console/helpers/questionhelper.rst +++ b/components/console/helpers/questionhelper.rst @@ -384,6 +384,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');