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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23588372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:49:09  来源:igfitidea点击:

Warning: array_keys() expects parameter 1 to be array, null given

php

提问by LisaW

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.

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

回答by

Init your "param":

初始化你的“参数”:

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

You may also see the PHP Doc

您还可以查看PHP 文档

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

回答by Ranjith

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

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

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