Skip to content
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

Merged
merged 3 commits into from Feb 2, 2017
Merged

Small phpdoc fix in Klein\Request #315

merged 3 commits into from Feb 2, 2017

Conversation

userlond
Copy link
Contributor

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:

<input type="hidden" name="id[]" value="1">
<input type="hidden" name="id[]" value="2">
<input type="hidden" name="id[]" value="3">
<?php
// $ids will contain array of ids
$ids = $request->param('id');

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');
```
@@ -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
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

@Rican7 Rican7 Feb 2, 2017

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:

@Rican7 Rican7 self-assigned this Feb 2, 2017
@Rican7 Rican7 added this to the 2.1 milestone Feb 2, 2017
Copy link
Member

@Rican7 Rican7 left a 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

Rican7
Rican7 approved these changes Feb 2, 2017
Copy link
Member

@Rican7 Rican7 left a 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! 👍

@Rican7 Rican7 merged commit 43d6725 into klein:master Feb 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants