Skip to content

Command::addOption()'s $default expects wrong array format #47

Closed
@Majkl578

Description

@Majkl578

Symfony 4.0 documents Symfony\Component\Console\Command\Command::addOption()'s 5th parameter $default as mixed.

When using default values with InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL mode, the $default parameter expects array<int, string>|null.
This is wrong because keys are irrelevant and leads to error like this:

Parameter #5 $default of method Symfony\Component\Console\Command\Command::addOption() expects array<int, string>|null, array<string> given.

Happens when $default is given an array documented as string[].

Sample code:

/** @var string[] $default */
$default = getSomeDefaults();

$command->addOption(
	'foo',
	null,
	InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL,
	'foo bar',
	$default
);

This error pops up at level 0 only with this extension enabled, not without it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions