7
考慮下面的代碼:爲什麼在PHP 7中調用可調用屬性有效?
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)();
會工作,如果屬性也包含在palenthesis中呢?所以我測試3v4l:
return ($this->inner)() . ' world';
And found that it works for PHP 7, but not for previous versions.
但是,我無法找到此in the changelogs的任何提及。
我在哪裏可以找到關於此功能的更多信息?