Re: Returning an object
| From: | Aidan Lister | Date: | Fri, 07 May 2004 21:36:41 +0000 |
| Subject: | Re: Returning an object | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-185688@lists.php.net to get a copy of this message | ||
I found some more information about it here:
http://bugs.php.net/bug.php?id=24687
It looks like you should assign an object to a variable before returning it.
"Justin Patrin" <papercrane@reversefold.com> wrote in message
news:20040507162911.65073.qmail@pb1.pair.com...
> Aidan Lister wrote:
>
> > How _should_ this be done? In terms of "best practice".
> >
> > <?php
> > function foobar ()
> > {
> > return new SomeObject;
> > }
> > ?>
> >
> > Or:
> >
> > <?php
> > function barfoo ()
> > {
> > $tempvar = new SomeObject;
> > return $tempvar
> > }
> > ?>
> >
> > Please don't reply if you really, really don't know what you are talking
> > about.
>
> Some earlier versions of PHP5 would not allow returning by reference of
> a function call or a new call. It was very recently added, but may not
> be in RC2 (not sure). You had to assign to a variable before you returned.
>
> Here's my 2c:
>
> function &foobar() {
> return new SomeObject;
> }
>
> --
> paperCrane <Justin Patrin>