4

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.

4

1 回答 1

10

你看到的是尤达条件。没有标准定义这些(至少据我所知)。它们只是一种保护自己免受常见编码错误(根据您的条件分配)的方法。

例子:

if( number = 4 ) // Works perfectly

if( 4 = number ) // Throws an exception
于 2012-08-20T11:39:43.233 回答