PHP & ZF2 / Comparison: expected == relevant

Does anyone know why some developers (especially in Zend Framework 2 sources) write the expected value to the actual value in comparison?

Example:

if (true === $actualValue) { ... } 

instead

 if ($actualValue === true) { ... } 

This case is not defined in the PSR coding standard.

Note: There is a similar topic for C ++, but without very useful answers.

+4
source share
1 answer

What you see are Yoda conditions . There is no standard defining these (at least to my knowledge). This is just a way to protect yourself from a common coding error (assignment in your conditions).

Example:

 if( number = 4 ) // Works perfectly if( 4 = number ) // Throws an exception 
+10
source

All Articles