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

[Command] Error when using a constant as argument/option default value #57

Open
@fsevestre

Description

Hello,

We have the following error messages while using a command argument/option default value as a constant:

 ------ ------------------------------------------------------------------------------------------------------------------------------ 
 42 Parameter #4 $default of method Symfony\Component\Console\Command\Command::addArgument() expects string|null, mixed given. 
 42 Parameter #5 $default of method Symfony\Component\Console\Command\Command::addOption() expects int|string|null, mixed given. 
 ------ ------------------------------------------------------------------------------------------------------------------------------

The following code should return the error:

 public const MODE_CREATED = 'created';
 protected function configure()
 {
 $this
 ->setName('abc')
 ->addArgument('a', InputArgument::REQUIRED, '', static::MODE_CREATED)
 ->addOption('b', null, InputOption::VALUE_REQUIRED, '', static::MODE_CREATED)
 ;
 }

Even if the constant value is a string, it's understood as mixed.


For the moment, to avoid the error message, I have a private method which returns the constant value and use it as default value.

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

        AltStyle によって変換されたページ (->オリジナル) /