Is there any reason to use isset()?

荒凉一梦 提交于 2019-12-06 07:49:10

Reason

The reason is, isset() will return boolean and doesn't throw a warning when you check for the existence of variable and proceed. Also, there is a possibility that, a variable may have zero values:

  1. false
  2. 0
  3. ""

But they will be already set.


Example

$varb = false;
$vari = 0;
$vars = "";

isset($varb) // true
isset($vari) // true
isset($vars) // true

if ($varb) // false
if ($vari) // false
if ($vars) // false

You use isset() to check if a variable has been declared.

The other method checks what value $var has. So if $var happened to contain false then the condition would be false but you wouldn't whether the variable wasn't set or the variable contained false.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!