我发现了一个错误 isset() 未按预期工作。
isset()
我发现它返回null而不是false;这怎么会发生?
我的测试代码:
echo 'COUNT : '.count($_GET).', ISSET : '.(isset($_GET['test'])==null);
返回:COUNT:0,ISSET:1
像 from the comments 请求。
isset() 没有返回 NULL ! 这是因为 comparison 哪个治疗 无效的 像 FALSE 。您可以在手册中看到: http://php.net/manual/en/language.types.boolean.php#language.types.boolean.casting
NULL
无效的
FALSE
此外,如果您查看 isset() : http://php.net/manual/en/function.isset.php
你会看到它只会回来 TRUE 或 错误的 :
TRUE
错误的
返回TRUE 如果var存在并且具有除NULL以外的值, 否则为FALSE。
现在要解决这个问题,您可以简单地更改 == 到此为止 === ,以便比较也比较类型。
==
===