Re: new keyword combined with other things...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Dec 7, 2010 at 1:55 PM, Paul M Foster <paulf@xxxxxxxxxxxxxxxxx>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

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux