Wednesday, 18 September 2013

Call function directly after constructor: new Object()->callFunction()

Call function directly after constructor: new Object()->callFunction()

As you might have seen in the title, my programming background is Java. In
Java you can do stuff like this
new Object().callSomeMethod();
without assigning the created Object to a variable, very useful and clear
coding if you only need this Object once.
Now in PHP i try to do the same
new Object()->callSomeMethod();
but here i get a 'Parse error: syntax error, unexpected '->'
(T_OBJECT_OPERATOR)'.
Is there a way to do this in PHP ?

No comments:

Post a Comment