John
John

Reputation: 123

Class functions back to back

What is this method called? I have tried to replicate this but I don't know what to Google to find similar results for explanation. Would much appreciate any information given on this, thanks. I believe I saw this done in Drupals framework.

$query->fields('...')->condition('...')->execute()->fetchAssoc();

Upvotes: 1

Views: 44

Answers (3)

jospratik
jospratik

Reputation: 1674

in drupal terms what is happening is, a query will be fired with 'fields' provided as input (the select clause), 'condition' to filter the records fetched (where clause) and execute to ultimately fire the query and return a output as associative array.

Upvotes: 0

curious_coder
curious_coder

Reputation: 2458

Its called as Method chaining and available from php5 onwards.
For more info check out
stackoverflow.com/questions/3724112/php-method-chaining

Upvotes: 0

Phil Cross
Phil Cross

Reputation: 9302

Its called method chaining. Its when your method returns itself (the object):

class testObject
{
   function testMethodOne()
   {
       return $this;
   }

   function testMethodTwo()
   {
       return $this;
   }
}

$obj = new testObject;
$obj->testMethodOne()->testMethodTwo();

Upvotes: 3

Related Questions