__invoke() On New

../_images/invoke_on_new.png

It is possible to create a new object by calling new on a previous object: PHP fetches the name of the class, then its constructor.

With the PHP 8.4 new syntax without parenthesis, it is also possible to chain the instantiation with a direct call. This calls the __invoke method.

This was not possible in previous versions.

See Also

PHP Features