The New And The Parenthesis

no-email (Damien Seguy), Damien Seguy
Fri, 10 Jan 2025 00:00:00 +0000

Where does PHP accept parenthesis in a ``new`` call?
First, no parenthesis is possible, as long as the constructor has no parameter.
Secondly, also, parenthesis are possible, after the class name.
Then, the parenthesis may be around the class name, as long as there is a constant which holds the name of the class. Bonus point for the class and the constant with the same name.
After that, there is a dynamic call, where the full name of the class is build, then used.
And the last one is the constant version, with an explicit ``::class`` operator.
Now, it would be great to have a syntax where the parenthesis are before the class name: no other language has that! So, for PHP 9, but more importantly: what for?