Is there any benefit of using null first in PHP?

后端 未结 5 1761
长发绾君心
长发绾君心 2020-12-11 15:42

Possible Duplicate:
Why do some experienced programmers write comparisons with the value before the variable?

5条回答
  •  Happy的楠姐
    2020-12-11 16:05

    It prevents you from accidentally assigning the value to a variable, especially when only using loose type comparison (==):

    if (self::$_instance = NULL) { … } // WHOOPS!, self::$_instance is now NULL
    

    This style of conditions is often called yoda conditions. Performance wise there is no difference, both statements are equivalent.

提交回复
热议问题