Lots Of Silly Arguments¶
By Greg Korba
<?php
class Foo {
public function __invoke(): self {
return new self();
}
public function bar(): self {
return $this();
}
}
var_dump(new Foo()()()()->bar()()()()());
PHP 8.4 drops the requirement of parenthesis around the new operator: it is possible to directly call a method on it.
Then, it is also possible to use an object as a method, by creating the __invoke() magic method. In this case, it returns a new instance of the class.
Finally, it is possible to call a function whose name is the result of a previous call.
The final result is quite impressive.
See Also¶
PHP Features¶
Last updated: 14 July 2026