-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Better error handling when misuse of ArgvInput with arrays #54147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Note that we usually don't merge DX improvements as bugfixes. Thus, you should target 7.1 for this change. |
if (array_filter($argv, 'is_array')) { | ||
throw new RuntimeException('Argument values expected to be all scalars, got array.'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching arrays feels a bit arbitrary. What about objects? Resources?
Should we instead check for values that cannot be cast to string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this (I'm not sure for the Stringable):
if (array_filter($argv, 'is_array')) { | |
throw new RuntimeException('Argument values expected to be all scalars, got array.'); | |
} | |
foreach($argv as $arg) { | |
if (!is_scalar($arg) && !$arg instanceof \Stringable) { | |
throw new RuntimeException(sprintf('Argument values expected to be all scalars, got "%s".', get_debug_type($arg))); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
86b7728
to
0d7641e
Compare
New PR #54576 targeting 7.1 |
… with arrays (symfonyaml) This PR was squashed before being merged into the 7.2 branch. Discussion ---------- [Console] Better error handling when misuse of `ArgvInput` with arrays | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | Fix #53836 | License | MIT ### Issue When we don't use `ArgvInput` correclty, and use array in $argv values, it returns different PHP fatal errors. See all details and how to reproduce it in the issue #53836 ### Solution In this PR - Add some DX with an exception explaining the problem, to avoid PHP fatal errors - Add tests** _____ Note : Old PR #54147 was targeting 5.4, see [this comment](#54147 (comment)) for more details Commits ------- 6f64cf4 [Console] Better error handling when misuse of `ArgvInput` with arrays
… with arrays (symfonyaml) This PR was squashed before being merged into the 7.2 branch. Discussion ---------- [Console] Better error handling when misuse of `ArgvInput` with arrays | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | Fix #53836 | License | MIT ### Issue When we don't use `ArgvInput` correclty, and use array in $argv values, it returns different PHP fatal errors. See all details and how to reproduce it in the issue symfony/symfony#53836 ### Solution In this PR - Add some DX with an exception explaining the problem, to avoid PHP fatal errors - Add tests** _____ Note : Old PR #54147 was targeting 5.4, see [this comment](symfony/symfony#54147 (comment)) for more details Commits ------- 6f64cf4f80 [Console] Better error handling when misuse of `ArgvInput` with arrays
Issue
When we don't use
ArgvInput
correclty, and use array in $argv values, it returns different PHP fatal errors.See all details and how to reproduce it in the issue #53836
Solution
In this PR
Note : Old PR #53838