2014-05-11 26 views
0

古怪的分析器錯誤:警告:array_keys()預計參數1是陣列,NULL給出

Notice: Undefined property: template::$param in 
    C:\xampp\htdocs\app\includes\classes\class.template.php on line 37 

Warning: array_keys() expects parameter 1 to be array, null given in 
    C:\xampp\htdocs\app\includes\classes\class.template.php on line 37 

Notice: Undefined property: template::$param in 
    C:\xampp\htdocs\app\includes\classes\class.template.php on line 37 

Warning: array_values() expects parameter 1 to be array, null given in 
    C:\xampp\htdocs\app\includes\classes\class.template.php on line 37 

代碼:

public function newParam($trans, $value) { 
    $this->param['{' . $trans . '}'] = $value; 
} 

public function getParam($content) { 
    $content = str_replace(
     array_keys($this->param), 
     array_values($this->param), 
     $content 
    ); 

    return $content; 
} 

請注意,這不是任何現有的解析器。

+0

看來,由於某種原因,你的'$這個 - > param'是'null'。 – Hamatti

+0

除了你在這裏的東西,我們需要看到你實際實例化這個類並調用'getParam()'的代碼。看起來''this-> param'在調用getParam()'的時候沒有被初始化。 $ param'屬性初始化爲類屬性,如'public $ param = array();'? –

+0

請發佈整個類聲明。我對'$ this-> param'包含什麼特別感興趣。 –

回答

1

初始化你的 「參數」:

function __construct() { 
    $this->param = array(); 
} 

您還可以看到PHP Doc

Creating/modifying with square bracket syntax 

An existing array can be modified by explicitly setting values in it. 

This is done by assigning values to the array, specifying the key in brackets. The key can also be omitted, resulting in an empty pair of brackets ([]). 

$arr[key] = value; 
$arr[] = value; 
// key may be an integer or string 
// value may be any value of any type 
相關問題