Why check both isset() and !empty()

后端 未结 10 2510
难免孤独
难免孤独 2020-11-21 23:48

Is there a difference between isset and !empty. If I do this double boolean check, is it correct this way or redundant? and is there a shorter way

10条回答
  •  无人及你
    2020-11-22 00:31

    "Empty": only works on variables. Empty can mean different things for different variable types (check manual: http://php.net/manual/en/function.empty.php).

    "isset": checks if the variable exists and checks for a true NULL or false value. Can be unset by calling "unset". Once again, check the manual.

    Use of either one depends of the variable type you are using.

    I would say, it's safer to check for both, because you are checking first of all if the variable exists, and if it isn't really NULL or empty.

提交回复
热议问题