so, back again with an instance of === not always yielding the same result as == when perhaps it should… it just so happens that code i just wrote, given an empty string, yields a different result comparing that string to “” when using the === operator rather than the == operator.
even more strange, my attempt to create a ‘canned’ test case for this fell flat. i was not able to duplicate the behavior except within the application in which i discovered it.
moral of the story? if you know you’re comparing a string to “”, don’t use strict comparison === in order to test for an empty string. use == instead.
| bookmark it! | ||||||
|
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Nov | ||||||
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | ||||
One Response
krisgale
June 16th, 2009 at 7:25 am
1update: i can’t be sure but i think this behavior of the strict comparator had to do with a NULL being returned from a database result. apparently NULL is not a string type and thus is not === to “”.
RSS feed for comments on this post · TrackBack URI
Leave a reply