When coding it’s generally a good idea to fail early. Preferably at compile time. Today I found a little piece of code in an example that showed how to do just that. Not only that but I was also reminded of just days ago when I failed to follow that advise and was forced to search quite extensively for the bug I’d introduced. The following quote is from this page.
$musictype = ('jazz' == $music) ? 'cool' : 'blah';
Another important point in the above example, when doing logical comparisons always put the variable on the right side, like above. If you forget an equal sign it’ll throw a parse error instead of just evaluating true and executing the statement. It really takes no extra time to do, so if this saves one bug it’s worth it.
This really is a wonderful piece of advice. Just by placing the constant before the comparison you automatically detect when you fail to write double equal signs.