if(0 == '%') echo “WTF, Php, why can't you compare things sanely?”

后端 未结 5 903
灰色年华
灰色年华 2021-01-13 03:31

I just reduced a crazy bug to what\'s in the title of this question. I\'m sure there\'s a Perfectly Reasonable Explanation for why Php thinks that 0 == \'%\' (or any other s

5条回答
  •  不知归路
    2021-01-13 04:15

    Using '===' (for exact, literal comparison -- the values must be the same type and also equal) instead of '==' solves this problem. With '==' it's trying to cast '%' to a number and 0 is the best it can do.

提交回复
热议问题