-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Php documentation for methods "setOption()/setArgument()" doesn't allow arrays as values #28354
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
Comments
Actually both methods should accept a value of any type except objects not implementing |
Additionally |
@chalasr What would be the use case to support anything besides strings and arrays of strings? I'd say that using anything else is likely to break under certain circumstances. |
@xabbuh imho that would be helpful in case you need to validate/build values with complex operations returning objects as results. Those results might have a meaningful default "string" representation which can be used as value. (e.g. imagine wrapping some strings with something like danielstjules/Stringy to perform some validation/transformation, then it would be possible to drop the resulting object without explicit casting) Does it make sense? |
@xabbuh I was thinking to the case where input values would be replaced after being casted/resolved e.g. by a console event listener (see also #19441). If you still think this is more risky than useful, then we should probably fix the |
…tInterface (liarco) This PR was squashed before being merged into the 2.8 branch (closes #28374). Discussion ---------- [Console] fixed PHPDoc for setArgument/setOption in InputInterface | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #28354 | License | MIT | Doc PR | Methods now accept a value of any type except objects not implementing __toString(). **Example use case:** when using array arguments/options I can't set them programmatically without getting errors about type mismatch (from the IDE). With this patch it now works as expected. Commits ------- 61529f3 [Console] fixed PHPDoc for setArgument/setOption in InputInterface
Hi, I'm working on a console application that deals with options registered as
InputOption::VALUE_IS_ARRAY
, but when I call$input->setOptions('my-option', ['value1', 'value2'])
during initialization/validation my IDE complains about the second argument not matching the documentation (string|bool
). The same applies to thesetArgument($name, $value)
method which is set tostring
only.Since I might have array values for both options and arguments, should it be included into the documentation? Is it right to set array values for options/arguments in a this way?
Here is my proposal for the doc update: (I don't know if "array" is better than "string[]" here...)
Thank you for your time, please let me know if you want me to send a pull request for this.
The text was updated successfully, but these errors were encountered: