note 74537 added to language.operators.logical

From: Date: Mon, 16 Apr 2007 13:44:22 +0000
Subject: note 74537 added to language.operators.logical
Groups: php.notes 
Request: Send a blank email to php-notes+get-125441@lists.php.net to get a copy of this message
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. ---- Server IP: 87.124.64.96 Probable Submitter: 82.144.250.86 ---- Manual Page -- http://www.php.net/manual/en/language.operators.logical.php Edit -- https://master.php.net/note/edit/74537 Del: integrated -- https://master.php.net/note/delete/74537/integrated Del: useless -- https://master.php.net/note/delete/74537/useless Del: bad code -- https://master.php.net/note/delete/74537/bad+code Del: spam -- https://master.php.net/note/delete/74537/spam Del: non-english -- https://master.php.net/note/delete/74537/non-english Del: in docs -- https://master.php.net/note/delete/74537/in+docs Del: other reasons-- https://master.php.net/note/delete/74537 Reject -- https://master.php.net/note/reject/74537 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125441) next »