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:[EMAIL PROTECTED] 
Sent: Thursday, October 09, 2003 5:13 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Returning a reference

* Thus wrote Wouter van Vliet ([EMAIL PROTECTED]):
> 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

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

Reply via email to