Skip to content

Commit a1b3df8

Browse files
symfonyamlfabpot
authored andcommitted
[Console] Better error handling when misuse of ArgvInput with arrays
1 parent 965f054 commit a1b3df8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Input/ArgvInput.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ public function __construct(?array $argv = null, ?InputDefinition $definition =
4949
{
5050
$argv ??= $_SERVER['argv'] ?? [];
5151

52+
foreach ($argv as $arg) {
53+
if (!\is_scalar($arg) && !$arg instanceof \Stringable) {
54+
throw new RuntimeException(sprintf('Argument values expected to be all scalars, got "%s".', get_debug_type($arg)));
55+
}
56+
}
57+
5258
// strip the application name
5359
array_shift($argv);
5460

Tests/Input/ArgvInputTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ public static function provideInvalidInput(): array
324324
new InputDefinition([new InputArgument('name', InputArgument::REQUIRED)]),
325325
'Too many arguments, expected arguments "name".',
326326
],
327+
[
328+
['cli.php', ['array']],
329+
new InputDefinition(),
330+
'Argument values expected to be all scalars, got "array".',
331+
],
327332
];
328333
}
329334

0 commit comments

Comments
 (0)