Source: medium.com

Method Chaining in PHP

Category: PHP, api

Method Chaining is nothing but the concatenation of multiple methods to increase readability of code and avoid putting all the code in the single function. One of the major changes between PHP4 and PHP5 is that in PHP5 method can return objects. We will first see the basics of method chaining and then we’ll look into examples with explanation. Method Chaining is mainly used to implement Fluent Interface in an object-oriented API to achieve code readability.

Note that method chaining is not Fluent Interface.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners