note 74537 deleted from language.operators.logical by colder
| From: | colder@php.net | Date: | Mon, 16 Apr 2007 16:41:00 +0000 |
| Subject: | note 74537 deleted from language.operators.logical by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-125444@lists.php.net to get a copy of this message | ||
Note Submitter: muratyaman at gmail dot com
Reason: in docs
----
I thought, many people might be using "and" instead of "&&" operator.
The following trap may catch some programmers coming from different backgrounds. The following shows
something quite misleading..
<?php
function f(){
return TRUE;
}
$a = FALSE;
$b = $a and $f();
$c = f() and $a; //just changing places of operands
$d = ($a and $f());//using paranthesis is safe
$bb = $a && $f();
$cc = f() && $a;
?>
Output variables and see this:
$a ==> FALSE;
f() ==> TRUE;
$b = $a and f() ==> FALSE
$c = f() and $a ==> TRUE --- WHAT!?
$d = ($a and f()) ==> FALSE
$bb = $a && f() ==> FALSE
$cc = f() && $a ==> FALSE
Cheers.