Skip to content

Commit

Permalink
Update questionhelper.rst
Browse files Browse the repository at this point in the history
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 symfony#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
  • Loading branch information
issamkhadiri1989 authored Jun 12, 2022
1 parent 0544743 commit 66f5cc9
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions components/console/helpers/questionhelper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 66f5cc9

Please sign in to comment.