检查NULL的PhP代码有什么问题?


What is wrong with this PhP code of checking NULL

static $result = NULL;
if  (!isNull($result))
{
    return $result;
}

这是一个延迟加载模式。我将$result初始化为NULL。然后检查它是否为NULL。如果是,计算数据

程序在那一行崩溃了。另外,isNull($result)返回null,而不是true或false。

有什么问题吗?

PHP中没有isNull函数,只有is_null

php中没有isNull函数,请使用is_null php函数。

is_null - 查找给定变量是否为NULL,如果var为NULL返回TRUE,否则返回FALSE

if(!is_null($var))
 if  (! is_null($result))
 {
     echo  $result;  // no return use echo
 }

is_null不是isNull

static $result = NULL;
if  (!is_null($result))
{
    return $result;
}

static $result = NULL;
if  (!is_null($result))
{
    return $result;
}

try

static $result = NULL;
if  ($result!==null)
{
    return $result;
}

您使用了错误的null函数进行检查,它不是isNULL,它是is_null

static $result = NULL;
if  (!is_nul($result))
{
    return $result;
}