Skip to content

Typed option definitions are not enforced when the option is passed without a value #38

Description

@HafizMMoaz

An option passed without a value is parsed as true. Command::validateDefinitions() skips any value that is not a string (src/Command.php:367), so a typed option silently passes validation and the command receives a bool where it expects a numeric string.

protected array $optionDefinitions = [
    'limit' => ['type' => 'int'],
];
php app typed 5 --limit
# no validation error
# $console->getOption('limit') === true

Verified on PHP 8.4.19 against main (2c0159f).

Expected: when a definition declares a type other than the implicit string, an option given without a value should fail validation with something like option "limit" must be of type int.. A definition may also want a way to say the option is a flag, so true stays valid for flags only.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions