Are these two expressions equivalent? If they are, can you explain why? (I am a java programmer):
if(!$someObject)
if($someObject!==null)
Thanks
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.
You can have a look a the type comparisons table on php.net
Plus in your case, if
$someObject = true, thenif($someObject!==null)works butif(!$someObject)won’t.In PHP you have the two different type of comparison, the loose one (
==,!=) and the strict one (===,!==).ifworks with a loose comparison.The second
ifyou use will basically work with strict comparison, so the two of them can’t be equivalent.The only way to have a real equivalent is to work with the same comparison “type” within the two if.
if(!$someObject)is equivalent toif($someObject == false)only.