News Feed
Jobs Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Mike Naberezny's Blog:
Fluent Interfaces in PHP
December 21, 2005 @ 06:59:39

Mike Naberezny has a new post on his blog today with a look at "fluent interfaces" in PHP. The concept of fluent interfaces is based on this structure, a method to make the code "flow" more.

Today on Martin Fowler's bliki, I read a great new article describing what he calls "fluent interfaces". Normally, most setter methods of an object will return void. In an object with a fluent interface, setters will instead return an object to promote object chaining.

In PHP 4, it was not possible to do chaining, but one of the great new features of PHP 5 is that it supports directly deferencing objects returned by methods. It might sound complicated, but it's really not and it has the potential to greatly improve the readability of some code. Let's take a look at how to implement a fluent interface in PHP.

He continues the post, giving a nice, simple (and clear) example of how to create these interfaces within the functionality that PHP provides. For PHP, the fluent interface is such that the setter methods return an object handle (such as a "return $this")...

0 comments voice your opinion now!
fluent interface programming style object handle fluent interface programming style object handle


blog comments powered by Disqus

Similar Posts

PHPMaster.com: Implementing PSR-3 with log4php

RubySource.com: PHP to Ruby: Modules, Mixins and Ducks

Stefan Mischook's Blog: OOP in PHP: New PHP Article in Web Designer Magazine (Nov 2006)

DevShed: Completing a Blogging Application with the Code Igniter PHP Framework

Wojciech Sznapka's Blog: Accessing private object property from other object in PHP


Community Events











Don't see your event here?
Let us know!


code package overview unittest introduction release facebook support framework hack composer component security application symfony2 opinion podcast hhvm language install

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework