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
Small phpdoc fix in Klein\Request #315
Conversation
Klein\Request::param may return null, if there is no key and default is null.
Also it may return array, if html form contains inputs like is like:
```html
<input type="hidden" name="id[]" value="1">
<input type="hidden" name="id[]" value="2">
<input type="hidden" name="id[]" value="3">
```
```php
<?php
// $ids will contain array of ids
$ids = $request->param('id');
```
src/Klein/Request.php
Outdated
| @@ -290,7 +290,7 @@ public function params($mask = null, $fill_with_nulls = true) | |||
| * | |||
| * @param string $key The name of the parameter to return | |||
| * @param mixed $default The default value of the parameter if it contains no value | |||
| * @return string | |||
| * @return string|array|null | |||
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.
Hmm, good point. This should likely just be mixed.
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.
According to https://www.phpdoc.org/docs/latest/guides/types.html type may be mixed, if "the author of the documentation is unable to predict which type it will be".
At the same time variable may have "multiple types combined", when "an element may accept or return a value that can be any of a limited set of Types".
If return type may be not in (string, array, null), it may be or appended, or declared as mixed :)
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.
Yea, I totally get that rule. It's just that the actual value of the param may be even more types, such as int, float, etc, depending on how the request body, route parameters, or other injected parameters, are parsed.
For example I have a JSON handler that decodes JSON request bodies from incoming requests that contain a Content-Type header with the value application/json and injects the decoded values into the parameters.
So yea, we can't truthfully accurately "predict" what types will be returned here.
There's prior art for this:
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.
Wow, you're quick!
If you don't mind, could you also update the matching error on line 327
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.
You're impressively quick to respond... Can I hire you?
This looks great! Thanks!
Klein\Request::param may return null, if there is no key and default is null.
Also it may return array, if html form contains inputs like is like: