note 113132 deleted from control-structures.if by levim
| From: | levim@php.net | Date: | Fri, 06 Dec 2013 21:31:45 +0000 |
| Subject: | note 113132 deleted from control-structures.if by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197825@lists.php.net to get a copy of this message | ||
Note Submitter: orrd101 at yahoo dot com
----
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();
?>