2

I've been looking through Zend Framework's source code and noticed that most (if not all) comparisons are done with the operands in the reverse order I would expect:

if ((false !== $request) { ... } 

instead of:

if (($request !== false) { ... } 

What is the reason for this convention?

2 Answers 2

6

It's called a Left-Hand Comparison.

Basically, it's so that if you forget to put the second = in ==, it'll error rather change the value of the variable...

Sign up to request clarification or add additional context in comments.

Comments

3
if (false = $request) 

will fail quickly (if you meant false == true for example) - you can't assign to a constant. It's one of those tips that you figure out, or see and follow, to help catch problems. The ZF convention of leaving off a close-PHP tag (?>) at the ned of a file is the same idea. You can't have whitespace that might be output an cause a problem, if there's no tag for it to follow.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.