警告:array_keys()期望参数1为数组,给定为null

时间:2014-05-11 02:39:50

标签: php

奇怪的解析器错误:

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;
}

请注意,这不是任何现有的解析器。

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

确保laravel> = 5.5的fideloper / proxy版本为4.0

"require": {
        "php": "^7.1.3",
        "**fideloper/proxy**": **"^4.0"**,