Is one more readable than the other? At first, I disliked the false ===
approach but as I see it more and more often, I'm warming up to it. I'm pretty sure they return identical results.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
There's absolutely no functional difference.
I usually prefer to place the variable first, and the constant value second. Because that makes sense (When you speak it out loud, would you say "I test that the variable is false"? Or "I test that false is equal to the variable"?)
I greatly prefer
Namely because sometimes you are only using equality and not looking for identity.
In which case you write
But sometimes you aren't at the top of your game, and might write
which will give an immediate error, and let's you fix it right away.
However, if you type
you end up beating your head against a wall for an hour trying to figure out why your script isn't working right.
A much better software engineer than me taught me about this. Long story short, placing the constant first is a best practice, although it may look weird at first. I say that it's a best practice because it results in the most predictable outcomes: