Does anyone know if the following expression will be possible in the next version(s) of PHP?
(new A())->a(); // Causes a syntax error
I find very annoying that currently one must write 2 lines instead of 1:
$c = new A(); $c->a();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The first version does not cause a parse error, it is perfectly valid. The second it is, indeed not possible, but you can easily overcome such a problem with some coding standards.
If every team member creates, for each defined class, a function with the same name as the class, and a signature similar to the signature of the class constructor, then you won’t have the second problem. Example:
Of course, you’ll still have problems with library code.