Quick silly question

i-CONICA
i-CONICA used Ask the Experts™
on
Hi,

Silly question maybe, and I'm pretty sure I already know the answer, but I thought I'd check..

Is there ever a situation where != false isn't exactly the same as == true? and vice versa, where != true same as == false?

Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
how, it will be such situation?

Commented:
Hello i-CONICA,

Is there ever a situation where != false isn't exactly the same as == true?
True, it could be that it is not exactly the same, as these comparisons are ignoring the type.

However !== false is exactly the same as === true

http://www.php.net/manual/en/types.comparisons.php

Regards,

alain34

Author

Commented:
I know about type comparisons, I know the difference between == and === and != and !== but that's not what I mean...

I've seen several times if($variable != false) and I've wondered why ($variable == true) wasn't used.

:)
$variable != false is exactly the same as $variable == true.

It just depends on the developer really to choose which they want.
Sometimes it feels more logical to check if something is not false.
One example might be if the variable was originally set to false, and you are checking if it has changed.

In the end though, yes they are both the same.

Author

Commented:
Perfect, thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial