Monday, October 15, 2007

ugly dynamic typing bug

In PHP, '0e00' == '00'. No, really. It's sick. Led to the nastiest bug I've ever seen in our hexadecimal permissions bitmasking at work: over a quarter of the time (whenever the hexadecimal string started with one or more zeros followed by a number greater than eight), permissions were wiped out. Fortunately, the bitmask is only a cache, so we didn't lose any data, but it was quite confusing. That'll teach me to use strict checking more often.

Update: after playing around with it a little more, we realized that it's interpreting it as scientific notation, not octal. (See php.net: string conversion to numbers.) The conversion itself is reasonable; the ridiculous part is comparing two strings and converting them both to floats.

2 comments:

Unknown said...

That's silly. Why does PHP even have a standard scientific notation comparison?

Samantha said...

Hey--thanks for the tips you left on my blog--but I think I'm just going to let Adam play for awhile. I'll give those to him after he's exhausted his own possibilities. :)