Re: Double method access (Hi everyone! :))

From: Date: Fri, 04 Mar 2011 19:33:15 +0000
Subject: Re: Double method access (Hi everyone! :))
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-311673@lists.php.net to get a copy of this message
That's called method chaining. ->getColumns() will get called on the object returned by ->getTable(). That is, getTable() returns an object (presumably representing an SQL table, I guess), and that object has a getColumns() method, which you call. This is an extremely common style in Javascript code that has been gaining widespread use in PHP OO circles in recent years. If leveraged properly it can create very compact, very readable, very powerful code. (And if done stupidly can lead to a horrid mess, but that's true of any coding style.) --Larry Garfield On 3/4/11 1:25 PM, Paola Alvarez wrote:
Hi there!, I have been reading this list before but this is my first post. Reading some code from Symfony I got this: $this->getTable()->getColumns() ...when you can use this double method access?, I used before the regular $this->getTable(), but two?. I mean I have been trying but I got an error* * Fatal error: Call to a member function ... on a non-object in ... Thanks! Paola PS: BTW, sorry my english isnt really good


« previous php.general (#311673) next »