Wi-Fizzle.com - Putting the fizzle in Wi-Fi since 2005 .. (yes, this was a poor choice for a domain name)

#277
PHP coding tip regarding variable-value comparison

Posted by dandriff on Monday June 30, 2008@12:22PM

This comment at php.net contains a valuable piece of wisdom:

If you need to compare a variable with a value, instead of doing:
<?php
  if ($foo == 3) bar();
?>

do:
<?php
  if (3 == $foo) bar();
?>

This way, if/when you forget the second equals sign (=), the statement will become:
<?php
  if (3 = $foo) bar();
?>

and PHP will evaluate the statement and report an error.