Re: Double method access (Hi everyone! :))
| From: | Vivek | Date: | Sat, 05 Mar 2011 13:13:31 +0000 |
| Subject: | Re: Double method access (Hi everyone! :)) | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-311691@lists.php.net to get a copy of this message | ||
I also totally agree with Larry that if used judiciously then method/object
chaining can give great results, else otherwise, can create a lot of
overhead in the application.
Netemp
On Sat, Mar 5, 2011 at 1:14 AM, Paola Alvarez <paola.alvarez85@gmail.com>wrote:
> Hi, thanks a lot Alex and Larry for your very clear answer!
>
> Paola,
>
> On Fri, Mar 4, 2011 at 4:33 PM, larry@garfieldtech.com <
> larry@garfieldtech.com> wrote:
>
> > 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
> >
> >
>