为什么 isset() return 为空?
Why would isset() return null?
我收到一个错误,发现 isset()
没有按预期工作。
我发现它返回的是 null 而不是 false;这怎么会发生?
我的测试代码:
echo 'COUNT : '.count($_GET).', ISSET : '.(isset($_GET['test'])==null);
returns:计数:0,ISSET:1
根据 要求。
isset()
没有返回 NULL
!这是因为 comparison which treats NULL
as FALSE
. You can see this in the manual: http://php.net/manual/en/language.types.boolean.php#language.types.boolean.casting
此外,如果您查看 isset()
的手册:http://php.net/manual/en/function.isset.php
你会看到它只有 returns TRUE
或 FALSE
:
Returns TRUE if var exists and has value other than NULL, FALSE otherwise.
现在要解决此问题,您只需将 ==
更改为 ===
,这样比较也会比较类型。
我收到一个错误,发现 isset()
没有按预期工作。
我发现它返回的是 null 而不是 false;这怎么会发生?
我的测试代码:
echo 'COUNT : '.count($_GET).', ISSET : '.(isset($_GET['test'])==null);
returns:计数:0,ISSET:1
根据
isset()
没有返回 NULL
!这是因为 comparison which treats NULL
as FALSE
. You can see this in the manual: http://php.net/manual/en/language.types.boolean.php#language.types.boolean.casting
此外,如果您查看 isset()
的手册:http://php.net/manual/en/function.isset.php
你会看到它只有 returns TRUE
或 FALSE
:
Returns TRUE if var exists and has value other than NULL, FALSE otherwise.
现在要解决此问题,您只需将 ==
更改为 ===
,这样比较也会比较类型。