In other words: equality is not intuitive. Awesome!
---
Let's take a look at "how PHP works":
0 == 08 // true!
WTF, really? Well, let's just use the magical 'I-mean-actual-equality-not-some-other-kind-of-equality' operator: 0 === 08 // also true!
(Sonofabitch/Facepalm) * Infinity
Of all the areas of a language in which one could gain expertise in, I think testing equality should not be one of the more difficult to master.This is just stupid behavior. 08 is an invalid octal sequence, but no error is raised. You can't detect this condition unless you do your own pre-parsing before allowing PHP to try to parse it!
decimal : [1-9][0-9]*
| 0
hexadecimal : 0[xX][0-9a-fA-F]+
octal : 0[0-7]+
integer : [+-]?decimal
| [+-]?hexadecimal
| [+-]?octal
"08" and "09" do not match any of these. php -r "var_dump(08);"
Yields "int(0)", while the case should rather be treated as a syntax error, if you ask me.The bottom line probably is that your literals just shouldn't have leading zeroes…
$v = validated_integer($user_input); // the user input 08
if($v == 0 || $v === 0) { // let's just be safe
// the Wrong Thing happens
}
This is a contrived example, sure. But you've never checked to see if a user input the number 0? Or a non-zero, positive integer?