2
m144
7y

I was working on a bug in a parser for the response from an api which returns 'n/a' when a certain measurement isn't available. The code was "if ($value == 'n/a')" and when this was true the value was rejected (language is php).
Some of you may instantly understand the problem here. I didn't. Some of the measurements were 0 which is ok, but for some reason it didn't accept them.
Then I discovered the bitter truth:
0 == 'n/a' is true!
Apparently php tries to convert the string to a number to compare it and if it fails it returns false, so false == 0

😞

Comments
  • 2
  • 0
    Should have pointed out that I knew how to solve the problem (by doing type comparison as well ===) but it took me a while to reach this line...
  • 0
    @m144 php really is so broken..
Add Comment