请考虑以下代码:
interface Doll
{
/**
* @return string
*/
function __invoke();
}
class LargeDoll
{
private $inner;
function __construct(Doll $inner)
{
$this->inner = $inner;
}
function __invoke()
{
return $this->inner() . ' world';
}
}
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为它期望$this->inner是一个方法,而不是一个可调用的属性.
然后它发生在我身上,就像有(new LargeDoll)();工作一样,如果财产也被包裹在paranthesis中呢?所以我在3v4l上测试了它:
return ($this->inner)() . ' world';
Run Code Online (Sandbox Code Playgroud)
但是,我在更改日志中找不到任何提及.
我在哪里可以找到有关此功能的更多信息?