Re: new keyword combined with other things...

From: Date: Tue, 07 Dec 2010 23:12:04 +0000
Subject: Re: new keyword combined with other things...
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-309898@lists.php.net to get a copy of this message
On Tue, Dec 7, 2010 at 1:55 PM, Paul M Foster <paulf@quillandmouse.com>wrote: > Here is an example from their [CodeIgniter] user manual: > > > $this->db->select('title')->from('mytable')->where('id', > $id)->limit(10, > 20); > This is known as a "fluent interface" because it attempts to make your code read more naturally--i.e. fluently. Each method returns either a new object or the same object ($this) so it can flow into the next method call. In the latter case, the initial object stored in $this->db implements all the above methods. I first saw this in mock object libraries for Java, but it was invented years earlier. $mock = $this->getMock('Calculator'); $mock->expect('add')->once()->with(3, 5)->willReturn(8); David

« previous php.general (#309898) next »