包括时不能用[]进行阅读

时间:2018-01-05 21:09:31

标签: php

我有这个PHP文件:

<?php

namespace FrameWork\Controller;

abstract class ControllerBase
{

    protected $action;
    protected $vars;

    public function __construct($action, $vars = NULL)
    {
        $this->action = $action;
        $this->vars = $vars;

        $this->populateVars();
    }

    public function run()
    {
        ****BETWEEN HERE****
        $r = new \ReflectionMethod($this, $this->action);
        $params = $r->getParameters();

        $funcParams[];

        foreach($params as $param)
        {
            $paramName = $param->getName();
            $funcParams[$paramName] = $this->vars[$paramName];
        }
        ****AND HERE****

        call_user_func_array(array($this, $this->action), $funcParams);
    }

    private function PopulateVars()
    {
        foreach($_GET as $key => $getVar)
        {
            $this->vars[$key] = $getVar;
        }

        foreach($_POST as $key => $postVar)
        {
            $this->vars[$key] = $postVar;
        }
    }
}

它是include在另一个文件中,由于某种原因,我在include上抛出异常。

Cannot use [] for reading

当我删除****BETWEEN HERE********AND HERE****之间的所有内容时,它会起作用(或者至少不会抛出相同的异常)。

知道发生了什么事吗?

1 个答案:

答案 0 :(得分:1)

您是否尝试过更换

$funcParams[];

$funcParams = array();

我认为它会解决你的问题。