PHP5 questions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

PHP5 questions

Post by Ree »

I know that by default PHP5 passes objects by reference. Does it by default return them by reference as well?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: PHP5 questions

Post by Chris Corbyn »

Ree wrote:I know that by default PHP5 passes objects by reference. Does it by default return them by reference as well?
Try it:

Code: Select all

class foo
{
    private $x, $y;
    
    public function setX($x)
    {
        $this->x = $x;
    }

    public function setY($y)
    {
        $this->y =$y;
    }
}

function test()
{
    $foo = new foo;
    $foo->setX(10);
    $foo->setY(2);
    return $foo;
}

$bar = test();

print_r($bar);

/*
 foo Object
(
    [x] => 10
    [y] => 2
)
 */
;)
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

Erm... I don't see the answer from your test? I doubt print_r ever describes anything as 'Reference'.
Post Reply