In WordPress' core code, you often see this:
if (1 == $someVar)
as opposed to this:
if ($someVar == 1)
I don't know if the first way is a WordPress-centric style of coding, but I've only noticed it in WP code (either core or 3rd-party code).
|
In WordPress' core code, you often see this:
as opposed to this:
I don't know if the first way is a WordPress-centric style of coding, but I've only noticed it in WP code (either core or 3rd-party code). |
|||||||||||||||||||||
|
|
This coding style is known as a Yoda Condition, and it's nothing specific to WordPress. I've used the same style in C++, C#, and even JavaScript code. The main benefit of a Yoda Condition is that it prevents accidental value assignment from a typo. Consider the following (often-seen-in-the-wild) typo:
This will always evaluate to
The point of this code is to assign a new value to the Yoda Conditions (reversing the order of the
Like I said, this is not unique to WordPress, or even to PHP, however it is part of the required WordPress coding standards. If you're writing a plugin or theme for general distribution, or contributing to core, you need to know both what Yoda Conditions are and how to use them |
|||||
|