How many among us can be 100% sure that if every string field we sent up to the server in either a form POST or GET parameters were set to the value "true", we'd not see the same issue...
The second link especially shows the truth of what is going on, with a "Type error: cannot set value 'true' to property 'lastName'"!!
So that seems like something great to try out in unit, or at least UAT testing...
This is really where the type-nonchalance of JSON comes to bite you on the ass as the entire chain from entry t
JSON has nothing to do with this. In JSON the value true is encoded as true, not "true". Even a bad JSON encoder/decoder wouldn't make this error, as it'd be incompatible with everything out there.
Remember that for the most part JSON is a subset of Javascript (there are minor supposed differences that never come up in the real world, but the structure is basically a JS object defined in terms of constants using the Javascript syntax.) If Javascript accepted the word "true" as meaning true, it'd be very, very, difficult to program in. It'd suck worse than PHP.
(And it's worth noting that while the default equality operator (and switch() statement) in PHP treats "0", "", null, 0, and false the same way, this isn't true of "true" values, and regardless of what the equality operator does, it doesn't store them or represent these values using the same internal structure. Just pointing out how batshit insane it would be for JSON to treat "true" and true as the same thing.)
Really excellent test case (Score:3)
How many among us can be 100% sure that if every string field we sent up to the server in either a form POST or GET parameters were set to the value "true", we'd not see the same issue...
The second link especially shows the truth of what is going on, with a "Type error: cannot set value 'true' to property 'lastName'"!!
So that seems like something great to try out in unit, or at least UAT testing...
This is really where the type-nonchalance of JSON comes to bite you on the ass as the entire chain from entry t
Re:Really excellent test case (Score:2)
JSON has nothing to do with this. In JSON the value true is encoded as true, not "true". Even a bad JSON encoder/decoder wouldn't make this error, as it'd be incompatible with everything out there.
Remember that for the most part JSON is a subset of Javascript (there are minor supposed differences that never come up in the real world, but the structure is basically a JS object defined in terms of constants using the Javascript syntax.) If Javascript accepted the word "true" as meaning true, it'd be very, very, difficult to program in. It'd suck worse than PHP.
(And it's worth noting that while the default equality operator (and switch() statement) in PHP treats "0", "", null, 0, and false the same way, this isn't true of "true" values, and regardless of what the equality operator does, it doesn't store them or represent these values using the same internal structure. Just pointing out how batshit insane it would be for JSON to treat "true" and true as the same thing.)