In PHP, can you instantiate an object and call a method on the same line?

The feature you have asked for is available from PHP 5.4. Here is the list of new features in PHP 5.4:

https://php-legacy-docs.zend.com/manual/php5/en/migration54.new-features

And the relevant part from the new features list:

Class member access on instantiation has been added, e.g. (new Foo)->bar().

Leave a Comment