-7
static $result = NULL;

if  (!isNull($result))
{
    return $result;
}

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

好吧,程序在那一行崩溃了。isNull($result) 也产生 null,而不是 true 或 false。

有什么问题?

4

7 回答 7

8

PHP中没有isNull函数,它是is_null

于 2013-03-04T10:10:52.890 回答
1

php中没有调用函数isNull使用is_nullphp函数。

is_null查找给定变量是否为 NULLTRUE如果 var 为 null 则返回,FALSE否则返回。

if(!is_null($var))
于 2013-03-04T10:12:35.623 回答
1
 if  (! is_null($result))
 {
     echo  $result;  // no return use echo
 }
于 2013-03-04T10:12:55.607 回答
0

is_null不是isNull

static $result = NULL;

if  (!is_null($result))
{
    return $result;
}
于 2013-03-04T10:11:11.483 回答
0

这将是

static $result = NULL;

if  (!is_null($result))
{
    return $result;
}
于 2013-03-04T10:12:17.630 回答
0

尝试

static $result = NULL;

if  ($result!==null)
{
    return $result;
}
于 2013-03-04T10:12:18.720 回答
0

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

static $result = NULL;

if  (!is_nul($result))
{
    return $result;
}
于 2013-03-04T10:14:10.397 回答