【发布时间】:2017-10-07 22:16:11
【问题描述】:
考虑以下代码:
interface Doll
{
/**
* @return string
*/
function __invoke();
}
class LargeDoll
{
private $inner;
function __construct(Doll $inner)
{
$this->inner = $inner;
}
function __invoke()
{
return $this->inner() . ' world';
}
}
这不起作用,因为它期望 $this->inner 是一个方法,而不是一个可调用的属性。
然后我想到,就像拥有(new LargeDoll)(); 一样,如果该属性也被包裹在括号中呢?于是我在 3v4l 上进行了测试:
return ($this->inner)() . ' world';
And found that it works for PHP 7, but not for previous versions.
但是,我找不到任何提及此in the changelogs。
我在哪里可以找到有关此功能的更多信息?
【问题讨论】: