Closed
Description
Symfony version(s) affected:
symfony/console v4.4.13 Symfony Console Component
Description
Referring to this class, https://github.com/symfony/console/blob/master/Input/ArgvInput.php, I ran into a situation where $argv
is NULL
by default and in turn caused $this->tokens
to be NULL
. This will cause an exception to be thrown when foreach()
is applied on $this->tokens
below:
- https://github.com/symfony/console/blob/a729c1d1f122a0f3a356f0882400d63cb44c9d5c/Input/ArgvInput.php#L243
- https://github.com/symfony/console/blob/a729c1d1f122a0f3a356f0882400d63cb44c9d5c/Input/ArgvInput.php#L279
How to reproduce
Many have reported about it in the past decade:
- https://stackoverflow.com/questions/57848968/invalid-argument-supplied-for-foreach-in-laravel-schedular-job
- https://laracasts.com/discuss/channels/laravel/invalid-argument-supplied-for-foreach-when-scheduling-task
- https://stackoverflow.com/questions/49149556/laravel-5-5-cron-job-proc-open-and-argvinput-problems
Possible Solution
Never allow $this->tokens
to be NULL
, at minimum, it should be an empty array.
- In
__construct()
, change the assign to call$this->setTokens($argv);
- In
setTokens()
,if (null == $tokens) $tokens = [];
Additional context
In the cases above (including my own), this exception does not link back to the offending code and becomes a real challenge to trace. I can submit a PR. Thank you.