L0t3k wrote:
Raffael,
    object in PHP5 _are_ passed by reference. internally, objects are
handles unique to a request, so all youre doing is passing a handle around.
note, however, that simple variable access will _always_ be faster than
method calls. this is true in C as well as PHP, except in PHP the effects
are more noticeable since it is interpreted rather than compiled.

l0t3k
Just to get things straight:

        <?php

        class Foo
        {
                public $foo = "bar";
        }

        $obj1 = new Foo;
        $obj2 = $obj1;
        $obj3 = $obj2;

        $obj2 = NULL;

        echo $obj1->foo;

        ?>

outputs

        bar

while

        <?php

        class Foo
        {
                public $foo = "bar";
        }

        $obj1 = new Foo;
        $obj2 =& $obj1;
        $obj3 =& $obj2;

        $obj2 = NULL;

        echo $obj1->foo;

        ?>

outputs

Notice: Trying to get property of non-object in /free1go/a/o/www.aoide.1go.dk/lab/bar.php5 on line 16

Hence, there is a difference between references and object handles. When you pass by reference,for instance $foo =& $bar, where $bar is an object, $foo will point to whatever $bar is pointing to. When you write $foo = $bar, $foo will point to the same object as $bar, but $foo is not forever bound to $bar, as in the first example. It simply has the same object handle. Therefore, when you delete $bar ($bar = NULL), $foo will be intact when using =, but will be set to NULL as well when using =&.


Cheers, Daniel

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



Reply via email to