There's an explanation on the WordPress site:
https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#yoda-conditions
It's called Yoda conditions; in short, it's because it's very easy for someone to mix up the assignment operator in PHP with the equality operator, so given a line of code:
if (x = true)
is almost certainly a typo, but won't generate any errors, because it's valid syntax.
On the other hand:
if (true = x) {
means that you're trying to assign the value of x
to the constant true
, and PHP will see that and generate an error message.
So it's an easy way to avoid some of the subtle syntax issues that PHP lets you get away with.