note 92939 added to language.operators.logical
| From: | ravenswd at gmail dot com | Date: | Sat, 15 Aug 2009 13:54:03 +0000 |
| Subject: | note 92939 added to language.operators.logical | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-159513@lists.php.net to get a copy of this message | ||
People seem to think that || and && are better to use than "or" and
"and" in every situiation. The reality is that it only matters in situations where one is
setting a variable equal to the result of a logical expression, as the previously-posted examples
illustrate. In almost every other use, || and "or" are equivalent:
<?php
if ($filename == '.' || $filename == '..') { continue; }
if ($filename == '.' or $filename == '..') { continue; }
?>
These two lines will produce exactly the same results, but the second line is (in my opinion)
clearer, because it uses an English word rather than an abstract symbol. If one is really worried
about operator precedence, one can always use parenthesis, like this:
<?php
if ( ($filename == '.') or ($filename == '..') ) { continue; }
?>
This version is clearest of all.
----
Server IP: 64.71.164.2
Probable Submitter: 67.165.168.203
----
Manual Page -- http://www.php.net/manual/en/language.operators.logical.php
Edit -- https://master.php.net/note/edit/92939
Del: integrated -- https://master.php.net/note/delete/92939/integrated
Del: useless -- https://master.php.net/note/delete/92939/useless
Del: bad code -- https://master.php.net/note/delete/92939/bad+code
Del: spam -- https://master.php.net/note/delete/92939/spam
Del: non-english -- https://master.php.net/note/delete/92939/non-english
Del: in docs -- https://master.php.net/note/delete/92939/in+docs
Del: other reasons-- https://master.php.net/note/delete/92939
Reject -- https://master.php.net/note/reject/92939
Search -- https://master.php.net/manage/user-notes.php