Consider the following code:
interface Doll { function __invoke(); } class LargeDoll { private $inner; function __construct(Doll $inner) { $this->inner = $inner; } function __invoke() { return $this->inner() . ' world'; } }
This will not work because $this->inner expected to be a method, not a property being called.
Then it occurred to me, just like work (new LargeDoll)(); will work, but what if the property were wrapped in paranthesis? So I tested it on 3v4l:
return ($this->inner)() . ' world';
And found that it works for PHP 7, but not for previous versions.
However, I cannot find mention of this in the change lists .
Where can I find more information about this feature?
php php-7
Adam elsodaney
source share