Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Console] PHP deprecation when question value is NULL #61122

Open
@willemverspyck

Description

@willemverspyck

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp