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

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

问题描述:

Weird parser errors:

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

Code:

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

Please note that this isn't any existing parser.

Init your "param":

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

You may also see the 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

Make sure fideloper/proxy version is 4.0 for laravel >= 5.5

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