Re: Returning a reference

From: Date: Thu, 09 Oct 2003 15:12:48 +0000
Subject: Re: Returning a reference
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-165607@lists.php.net to get a copy of this message
* 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(); Curt -- "My PHP key is worn out" PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/

« previous php.general (#165607) next »