RE: [PHP] Returning a reference [pretty much SOLVED]

From: Date: Thu, 09 Oct 2003 20:50:10 +0000
Subject: RE: [PHP] Returning a reference [pretty much SOLVED]
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-165666@lists.php.net to get a copy of this message
Thanks Curt. This solution works indeed. BUT, there's one but. Isn't there a way to not have to tell PHP that I want the return of $this->AddFoo() as a reference? In the actual code I want to worry as little as possible about specific things like this. Isn't it a little strange that you have to both let php know it's returning a reference as well as let it know that it's expecting a reference as return value? Wouter -----Original Message----- From: Curt Zirzow [mailto:php-general@zirzow.dyndns.org] Sent: Thursday, October 09, 2003 5:13 PM To: php-general@lists.php.net Subject: Re: [PHP] Returning a reference * Thus wrote Wouter van Vliet (wouter@esctoday.com): > Hi Folks, > > I've been using the "passing arguments by reference" thingie for a while > now. But what I want to do know is something I'm used to using in perl, > returning a reference. > > Situation is as follows. > > 19 > 20 function AddFoo() { Need to let php know this is returning a reference: function &AddFoo() { > 21 $Ref = &$this->Foos[]; > 22 $Ref = new Foo(); > 23 return $Ref; I'm surprized this even works, its kind of confusing, i'd rather do something like: $foo = new Foo(); $this->Foos[] = &$foo; return $foo; > 26 > 27 $Bar = new Bar(); > 28 $Foo = $Bar->AddFoo(); And then let php know you want this as a reference: $Foo = &$Bar->AddFoo(); <-- don't forghet the $ sign Curt -- "My PHP key is worn out" PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#165666) next »