does anyone know why some developers (especially seen in the sources of Zend Framework 2) write the expected value before the actual value in comparisons?
Example:
if (true === $actualValue) { ... }
instead of
if ($actualValue === true) { ... }
This case is not defined in the PSR coding standard.
Note: There is a similar topic for c++ but without really helpful answers.
What you are seeing is Yoda conditions. There is no standard defining these (at least not to my knowledge). They are merely a way to protect yourself against a common coding error (assignment in your conditions).
Example:
if( number = 4 ) // Works perfectly
if( 4 = number ) // Throws an exception
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With