note 113132 added to control-structures.if
| From: | orrd101 at yahoo dot com | Date: | Tue, 03 Sep 2013 16:04:35 +0000 |
| Subject: | note 113132 added to control-structures.if | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-196152@lists.php.net to get a copy of this message | ||
In the past it has been suggested that when comparing values you should reverse the logical order so
that if you accidentally use a "=" instead of a "==" PHP will generate an error.
For example:
<?php
if (3 == $foo) bar();
?>
Please consider that while there may be some limited benefit for programmers who have difficulty
remembering to use "=" instead of "==", that small benefit may not be worth
sacrificing readability and sensible logical order in your code.
This becomes even more obvious when a function call is involved. The code "if (strtolower($a)
== 'foo')" is far more logical and understandable to humans than "if
('foo' == strtolower($a))".
So instead, for most code it makes sense to simply use the logical order when writing comparison
statements like this:
<?php
if ($foo == 3) bar();
?>
----
Server IP: 69.147.83.199
Probable Submitter: 99.88.245.232
----
Manual Page -- http://php.net/manual/en/control-structures.if.php
Edit -- https://master.php.net/note/edit/113132
Del: integrated -- https://master.php.net/note/delete/113132/integrated
Del: useless -- https://master.php.net/note/delete/113132/useless
Del: bad code -- https://master.php.net/note/delete/113132/bad+code
Del: spam -- https://master.php.net/note/delete/113132/spam
Del: non-english -- https://master.php.net/note/delete/113132/non-english
Del: in docs -- https://master.php.net/note/delete/113132/in+docs
Del: other reasons-- https://master.php.net/note/delete/113132
Reject -- https://master.php.net/note/reject/113132
Search -- https://master.php.net/manage/user-notes.php