Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Open
Description
Symfony version(s) affected
6.4
Description
I get this deprecation notice, when I start typing in the console:
deprecation.INFO: Deprecated: str_starts_with(): Passing null to parameter#1 ($haystack) of type string is deprecated {"exception":"[object] (ErrorException(code: 0): Deprecated: str_starts_with(): Passing null to parameter#1 ($haystack) of type string is deprecated at /data/vendor/symfony/console/Helper/QuestionHelper.php:357)"} {"token":null}
The value of the ChoiceQuestion array should not be NULL, but I can happen. When I initate the command with "bin/console app:task", and press for example 2, I will get the deprecation notice (before pressing enter).
How to reproduce
#[AsCommand(name:'app:task', description:'Execute task for module')]finalclass TaskCommandextends Command{protectedfunctionconfigure():void {$this ->addOption('moduleId',null, InputOption::VALUE_REQUIRED,'The "id" of the module?'); }protectedfunctioninteract(InputInterface$input,OutputInterface$output):void {$moduleId =$input->getOption('moduleId');if (null !==$moduleId) {return; }$data = [1 =>'Foo',2 =>'Bar',3 =>null, ];$question =newChoiceQuestion('Please select a module:',$data);$question->setMaxAttempts(2);$question->setValidator(function (string$answer):string {if (0 ===preg_match('/^\d+$/',$answer)) {thrownewRuntimeException('Unknown module'); }return$answer; });$answer =$this->getHelper('question')->ask($input,$output,$question);$input->setOption('moduleId',$answer); }protectedfunctionexecute(InputInterface$input,OutputInterface$output):int {return Command::SUCCESS; }}
Possible Solution
Add nullsafe
Additional Context
No response