Closed avi123 closed 11 years ago
I do agree with you. Input::has($key)
should check that the key exists and ignore that the value is falsy.
Technically, you are right that we can do that, but there's a broader argument that false is a valid value. I believe the source code isn't validating that the value is non-falsy - they are checking if the stringified version of the value !== ''. For url encoded postbacks, this is valid, as false would be "false" or "0", ergo not a 0 length string. I think the paradigm just fails to consider JSON type post data
On Mon, Jun 24, 2013 at 3:21 PM, George Robinson notifications@github.comwrote:
I think the reason for Input::has($key) checking that the key exists _and_that the value is non falsy is so you don't need to use an if statement. This following code does the same as yours above.
$muppet->isBear = Input::has('isBear');
— Reply to this email directly or view it on GitHubhttps://github.com/laravel/framework/issues/1735#issuecomment-19929305 .
Fixed.
Imagine the following is posted from client:
{ "muppet": { "name": "Kermit", "isBear": false } }
The following server code won't execute correctly:
$muppet = new Muppet(Input::get('name));
if(Input::has('isBear')) { $muppet->isBear = Input::get('isBear'); }
isBear IS part of the Input array, however, Input::has function casts the value to string and then checks to see if it is empty, and in PHP, false casts to empty. Input::has should probably use isset or array_key_exists if the input type is JSON.