-
-
Notifications
You must be signed in to change notification settings - Fork 116
Typehinted integer in PHP 7 is ommited from generated URL when it's zero #112
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
Conversation
UIRuntime: unnecessary required parameters
ad16e59 to
1ba768a
Compare
|
I would love to fix it but honestly don't know how :( PresenterComponentReflection::convertType() correctly processes the parameter as zero. |
|
Actual result is IMHO fine. |
|
IMO is't a bug. |
|
I think it's a bug too. "int" represents all integers including negative ones and zero and I don't see a reason why a |
|
This
|
|
|
|
I too think it's a bug unless the action is with default value ( |
|
So what it should do when |
This question is about matching URLs and this PR is about constructing them. But I'd say in this case the result of |
|
When |
|
i.e. it should throw 500 error? Ohh… |
|
It means that the router is misconfigured/implemented poorly so I'm fine On Thursday, 21 January 2016, David Grudl notifications@github.com wrote:
Ondřej Mirtes |
👍 |
|
It is not about router. We are talking about And 500 means server error. Server error due to the removal of a single parameter from URL? Boys! Do not be silly :-) |
|
As I proposed couple of years ago, missing required parameter (or wrong type, e.g. |
|
I want the HTTP request to give me an integer. If there's no integer in the request, I have to respond with an error. What kind of error is a subject to discuss. I think this layer of request processing should be stopped at the router level. If an incorrect type is received by a presenter (involving some lossless type casting), something is very wrong and I would like this situation to result in a new error log line. So I'm voting for a 500 error. But if Nette wants to be more loose in these situations, I can accept throwing 404 too. |
|
@dg: The issue was about generated URLs, not their handling. Also I see a huge difference now that we have PHP 7 with scalar types. In the old times we often used default value (e.g. |
|
Possibly related (5 years old) forum thread https://forum.nette.org/cs/6819-validace-parametru-v-presenterech but due to it's age lot's of information and ideas may be outdated |
It doesn't mean, that the resource does not exist. You didn't fullfill the contract, server failed to do his job. That's all. I'm probably ok with 400. But 404 is non-sence. |
|
Btw, you probably look for 422: http://www.restpatterns.org/HTTP_Status_Codes/422_-_Unprocessable_Entity |
|
Can we go back to the original issue of constructing URL with zero integer as a parameter and create a new thread for support for scalar typehints in presenters and how to solve receiving requests with them? Thank you. |
This is obviously a good idea, but the giant BC break.
It does :-) It gives you 0. Btw, whether it is, number of page or id, you have to validate it.
Absolutely not. There's nothing to discuss, it just needs to be BadRequestException. (ie. 4xx, imho 404 is fine)
How can you define in router, that the query must contains a parameter @Majkl578 The issue was about generated URLs, not their handling. Generating and matching are very close. We cannot discuss about first one and aviod discussion about second one. |
If there's a missing parameter in the request, I don't want a random integer. Zero has the same weight as any other integer.
|
No, it is complex problem. You have to take into account the compatibility. What happens when someone will upgrade PHP 5 (ad router: I mean query part of URL). |
|
|
👍 |
|
@pilec: 422 is not valid for this case, because request URI is not an entity (entity = http body). |
I think that 2) is impossible and 1) vs 3) is about consistency (ie. a about different handling of IMHO 1) is best way. |
👍 , still, I'm more for 400. |
|
400 is perfectly ok, I'll try to find out how it affects Google. For example, 410 is big problem, because Google will ignore this URL, although it becomes exist in future. (And maybe that's not true anymore.) |
|
400 is good from the point of view of the HTTP spec, but it will likely cause people having to write a new latte template or change their code in the ErrorPresenter. |
|
I think that the best choice for Nette 3 is (1) + change array typehint behavior to match other typehints (BC break) + possibly implement support for class typehints (e.g ˙show (Article $article)˙) |
|
Class type hints are IMHO not needed, because object is created in router, which is tightly coupled with presenter. Now I realized that they are already suppoted! |
|
I forgot to mention persistent parameters - so 1) makes inconsistency between typehinted parameters and persistent parameters, because properties in PHP cannot have typehints. It is possible to use annotation |
It is tricky, because it is not possible to have empty array in URL. In fact, array is consistent with both solutions. |
|
Random thoughts:
|
…type hint, no default value and argument is missing [Closes #112]
…type hint, no default value and argument is missing [Closes #112]
…default value and argument is missing [Closes #112]
…default value and argument is missing [Closes #112]
…default value and argument is missing [Closes #112]
…default value and argument is missing [Closes #112]
…default value and argument is missing [Closes #112]
…default value and argument is missing [Closes #112]
…default value and argument is missing [Closes #112]
|
Cool, thanks! 👍 |
|
Great! Thank you! |
|
Looks great 👍 |
The attached commit shows the described situation.
Expected result of
$this->link('edit', ['id' => 0]):Actual: