php7 捕获语法错误,PHP7 method_exists未捕获错误:函数名称必须是字符串

这是由于处理间接变量和方法的评估顺序为

incompatible changes:

Changes to the handling of indirect variables, properties, and methods

Indirect access to variables, properties, and methods will now be evaluated strictly in left-to-right order, as opposed to the previous mix of special cases. The table below shows how the order of evaluaiton has changed.

不,你不必改变这一行:

$item['function']($item, $default);

因为在这里没有特别的评估,它只会使用数组元素作为函数名称并调用该函数.您可以更改它,并且代码仍然可以正常工作,但没有必要.

但正如你已经做的正确,你必须改变:

$this->$item['function']($item, $default);

至:

$this->{$item['function']}($item, $default);

↑ ↑

因为你可以看到这个table:

Old and new evaluation of indirect expressions

Expression PHP 5 interpretation PHP 7 interpretation

-------------------------------------------------------------------------------

$$foo['bar']['baz'] | ${$foo['bar']['baz']} | ($$foo)['bar']['baz']

$foo->$bar['baz'] | $foo->{$bar['baz']} | ($foo->$bar)['baz']

$foo->$bar['baz']() | $foo->{$bar['baz']}() | ($foo->$bar)['baz']()

Foo::$bar['baz']() | Foo::{$bar['baz']}() | (Foo::$bar)['baz']()

PHP 7将假设您首先要访问对象属性,然后要访问该属性的索引,并使用其值作为方法名来调用方法(从左到右的顺序).

要使用变量和索引作为属性名称,您必须使用花括号表示.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值