according to :
$ php -a
Interactive shell
php > var_dump("0" != 0);
bool(false)
php > var_dump(0 != null);
bool(false)
php > var_dump("0" != null);
bool(true)
can you explain why the last assertion is true ?
By the way, it is PHP cli 5.3.6.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is defined in the manual page PHP type comparison tables.
I find some of these very unintuitive.
"0" == falseis for example retarded since you often may have a form where the user inputs the number0. Now you need to check if a field is set using isset instead of just doing aif($field). Also note thatempty("0") == true!That’s why I use
===to get type-checked comparisons or use a language without automatic type casts.