代码之家  ›  专栏  ›  技术社区  ›  Владимир

严重错误:未捕获错误:函数名必须是字符串

php
  •  0
  • Владимир  · 技术社区  · 8 月前

    错误-严重错误:未捕获错误:函数名必须是blog.class.php第31行中的字符串

    请问原因是什么?PHP 7.1

    我尝试过不同的选择,但我不擅长PHP。

    public function route()
    {
        $res = bff::route(array(
                'blog/(.*)\-([\d]+)'     => 'blog/view/id=$2',
                'blog/tag/(.*)\-([\d]+)' => 'blog/listingTag/tag=$2',
                'blog/(page\d+\/?)'      => 'blog/listing/page=$1',
                'blog/(.*)'              => 'blog/listing/cat=$1',
        ), true
        );
    
        if ($res['event'] === false || !method_exists($this, $res['event'])) {
            $res['event'] = 'listing';
        }
    
        return $this->$res['event']() ;
    }
    
    1 回复  |  直到 8 月前
        1
  •  1
  •   Barmar    8 月前

    问题是

    $this->$res['event']()
    

    解析为

    ($this->$res)['event']()
    

    因此,它预计 $this->$res 成为一系列函数。

    但根据之前的代码,它看起来像 $res['event'] 应该是方法的名称。因此,您需要覆盖此默认分组。要将表达式用作动态方法或属性名称,请将其放入 {} .

    return $this->{$res['event']}();
    
    推荐文章