“条件==$variable”样式的优点


Advantage of "condition == $variable" style?

我经常看到是否像:

if (null === $var)  

我想知道使用它是否有任何技术优势?

发现它在语义上是错误的,我不喜欢它。喜欢

if ($var === null)

因为我要求变量的条件,而不是具有条件的变量。

这种类型的条件有时被称为尤达条件。它们的主要优点是避免了意外分配:

if ($foo = 'bar')
    echo 'Evaluates to true, and reassigns $foo silently';
if ('bar' = $foo)//error

除此之外,这是个人喜好的问题