Home >Backend Development >PHP Tutorial >Can You Instantiate an Object and Call a Method on the Same Line in PHP?
Instantiating an Object and Calling a Method on the Same Line in PHP
In PHP, there are two ways to instantiate an object and call a method:
The second method is only available in PHP 5.4 and later. It allows you to instantiate an object and call a method on the same line, which can be more concise and readable in some cases.
This feature was added to PHP in response to user requests for a more concise way to instantiate an object and call a method. It is particularly useful for chaining method calls, as it allows you to avoid having to store the object in a variable.
The above is the detailed content of Can You Instantiate an Object and Call a Method on the Same Line in PHP?. For more information, please follow other related articles on the PHP Chinese website!