可能重复:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”
我收到了错误:
注意:未定义的变量:null
代码行是:
$input = new $class($company, null, $sablonas, $null, $value);
类构造函数是:
public function __construct($company, $document, $sablonas, $options, $value = null) {
如何传递 null 值?
答案 0 :(得分:6)
$input = new $class($company, null, $sablonas, $null, $value);
// ^ ^
// (1) (2)
它在讨论的是(2)
,而不是(1)
。您的拼写错误为$null
。
通知消息“Undefined variable:null”在这里有点误导,但请考虑以下情况:
<?php
error_reporting(E_ALL | E_NOTICE);
echo $lol;
// Output: "Notice: Undefined variable: lol in /t.php on line 3"
?>
您可以看到$
未包含在通知消息为您提供的名称中,因此如果您遵循此逻辑,则会得出我在此答案顶部所做的结论。
答案 1 :(得分:4)
您有$null
作为变量:
$input = new $class($company, null, $sablonas, $null, $value);
//------------------------------------------^^^^^^^^^^
// Guessing that's supposed to be
$input = new $class($company, null, $sablonas, null, $value);
//-------------------------------------------^^^^^^^^
答案 2 :(得分:-2)
$null = NULL;