12
skanna
8y

When a condition is true and false at the same time...

var_dump(0 == "x"); // true
var_dump(!0 == " x"); // true

WTF?!

I started using the === more often...

Comments
  • 2
    It can totally be "x" and !" x" <- notice the space?
  • 0
    @fatlard1993 sorry space has been added by mistake probably by the mobile keyboard :/
    Try executing them (without that space in the string)
  • 0
    Isn't !"x" just "x"?
    !(O == "x") should return false should it not?
  • 0
    @TheBoJaN if you `(bool) 0` === false, while if you `(book) !0` === true.
    this means the String "x" is at the same time a true value (because it's a not-empty string) and a false value (because a theoretical hex"0x0" would be 0 in integer, so a false)
  • 0
    Interesting. I'd assume PHP would not know what to do with the ! Operator in that case and return the value of O to avoid errors, but I haven't touched PHP in over 10 years so idk
Add Comment