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

Appearance settings

[Console] PHP 8.1 PHP Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated #45179

Copy link
Copy link
Closed
@Rezyan

Description

@Rezyan
Issue body actions

Symfony version(s) affected

6.0.2

Description

Hi,

With Symfony/Console 6.0.2 and PHP 8.1, there is a depreciation on the method Symfony\Component\Console\Question\ChoiceQuestion::getDefaultValidator() (click on the link to see the line of the issue) :

PHP Deprecated : trim() : Passing null to parameter #1 ($string) of type string is deprecated.

This happens when the default value for the question is null.

How to reproduce

// Method definition : https://github.com/symfony/console/blob/v6.0.2/Style/SymfonyStyle.php#L277
$io->choice('Select the queue to analyze', ['queue1', 'queue2', 'queue3']); // The 3rd argument must be `null`.

Possible Solution

We can simply cast the variable to string to fix the issue. Just like this at this line:

-$selectedChoices[$k] = trim($v);
+$selectedChoices[$k] = trim((string) $v);

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.