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

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

 



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


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[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