Skip to content

Conversation

symfonyaml
Copy link
Contributor

@symfonyaml symfonyaml commented Mar 4, 2024

Q A
Branch? 5.4
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 #53838

@derrabus
Copy link
Member

derrabus commented Mar 4, 2024

Note that we usually don't merge DX improvements as bugfixes. Thus, you should target 7.1 for this change.

@derrabus derrabus added DX DX = Developer eXperience (anything that improves the experience of using Symfony) and removed Bug labels Mar 4, 2024
Comment on lines +50 to +52
if (array_filter($argv, 'is_array')) {
throw new RuntimeException('Argument values expected to be all scalars, got array.');
}
Copy link
Member

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?

Copy link
Member

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):

Suggested change
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)));
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GromNaN Applied your suggestion in the new PR #54576 targeting 7.1
Thank you

@symfonyaml
Copy link
Contributor Author

New PR #54576 targeting 7.1

@symfonyaml symfonyaml closed this Apr 12, 2024
@symfonyaml symfonyaml deleted the bug-console-argv-input-2 branch April 12, 2024 08:54
fabpot added a commit that referenced this pull request Jun 3, 2024
… 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
symfony-splitter pushed a commit to symfony/console that referenced this pull request Jun 3, 2024
… 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Console DX DX = Developer eXperience (anything that improves the experience of using Symfony) Status: Needs Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants