Detecting insufficient PHP variables: FALSE vs NULL vs unset() vs empty()?

前端 未结 3 864
花落未央
花落未央 2021-01-07 10:35

What is the best way to define that a value does not exist in PHP, or is not sufficent for the applications needs.

$var = NULL, $var = array()

3条回答
  •  孤街浪徒
    2021-01-07 10:54

    Another thing to remember is that since php is liberal in what it allows to evaluate to NULL or empty, it's necessary to use the identity operators (===, !== see http://php.net/operators.comparison. This is the reason why all of these comparison and equality functions exists, since you often have to differentiate between values with subtle differences.

    If you are explicitly checking for NULL, always use $var === NULL

提交回复
热议问题