The following PHP code is valid:
$a = new MyClass();
$a->myFunction();
Is there a valid way to combine these two statements? My first attempt understandably results in a syntax error:
new MyClass()->myFunction();
I then added brackets around the created object, and that ran fine on PHP 5.4.17 but not on PHP 5.3.26:
(new MyClass())->myFunction();
At what point is this syntax accepted, or should I abandon this idea and just use two lines. My actual use case is more complicated and it would make the code much neater if I didn't have to keep creating single-use variables all the time.
I am unable to find anything about this in the documentation.