atrum Posted October 4, 2011 Share Posted October 4, 2011 So, I recently discovered what method chaining is and how it can be used. My question about method chaining is in regards to best practice. What I want to know is what the correct way to implement methods that can be chained are, and what pitfalls will I need to watch out for when using them? Quote Link to comment https://forums.phpfreaks.com/topic/248432-method-chaining-and-how-to-use-it-correctly/ Share on other sites More sharing options...
trq Posted October 5, 2011 Share Posted October 5, 2011 There is nothing special about it. Any method that wouldn't normally return a value (setters for example) should simply return $this. Quote Link to comment https://forums.phpfreaks.com/topic/248432-method-chaining-and-how-to-use-it-correctly/#findComment-1275864 Share on other sites More sharing options...
atrum Posted October 5, 2011 Author Share Posted October 5, 2011 So there really is no right or wrong way to use them then other than trying to keep them primarily for Setter use. Cool, thank you Thorpe. Quote Link to comment https://forums.phpfreaks.com/topic/248432-method-chaining-and-how-to-use-it-correctly/#findComment-1276034 Share on other sites More sharing options...
ignace Posted October 5, 2011 Share Posted October 5, 2011 You can use them on any function that doesn't return a value. It's not exclusive for setters. Quote Link to comment https://forums.phpfreaks.com/topic/248432-method-chaining-and-how-to-use-it-correctly/#findComment-1276176 Share on other sites More sharing options...
atrum Posted October 5, 2011 Author Share Posted October 5, 2011 Ok, thanks Ignace. Quote Link to comment https://forums.phpfreaks.com/topic/248432-method-chaining-and-how-to-use-it-correctly/#findComment-1276228 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.