CakeMail Logo

CakeMail Blog

Email marketing for small businesses

Method Chaining in PHP

Posted on November 17, 2010

Written by


  • Maxime Jobin

    I use Zend Framework when developing with PHP and it uses method chaining in many classes. I love this concept!

    The code gets clean and is easier to read in my opinion!

    Good article!

  • cjoudrey

    I’m glad you liked it and thanks for the RT! :)

  • Andrew

    Personally I’d prefer being able to pass in a single “options” object that override sensible defaults, just like we do in jQuery. Of course in PHP it’d have to be an associative array, which doesn’t look nearly as nice or compact as JSON…

    'value' => 'cjoudrey',
    'expires' => 0,
    'domain' => ''

  • cjoudrey

    A few people have mentioned this on Reddit.

    The issue with passing an associative array is that you lose auto-completion from your editor.

    It could work if you are working alone on the project since you know how the function works, but once there is many people involved it could become a problem.

  • Jamie M

    You can do some really odd things if you combine method chaining with magic methods:

  • Montreal Web Design

    Method chaining is useful for creating simple dsls