Re: use of = &new object versus = new object
| From: | Malk0 | Date: | Mon, 11 Jul 2005 18:40:46 +0000 |
| Subject: | Re: use of = &new object versus = new object | ||
| References: | 1 2 3 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-5978@lists.php.net to get a copy of this message | ||
Hi Jake,
in php4 when you create an object like $object = new objectclass();
you will work on a copy of the object and so it's preferable to use
$object = &new objectclass();
This way you're sure to always work on the same instance of the object
not a copy.
Working with php-gtk1 you would better create object by reference not
copy, this way you will be sure to work on the good instance of the
object even in function as you will pass reference on the object not a
copy of it!
hope this is a little more clear to you now.
nathan
2005/7/11, Jake Gordon <php-gtk@jakeg.co.uk>:
> Thanks for quick replies, but I still don't get it.
>
> > & is to force an reference of object, under PHP5 references are
> deprecated
>
> Okay, but its creating a *new* object, so what exactly is it
> referencing? (PS, i'm using PHP4)
>
> Also...
>
> > in PHP the & means pass by reference. In PHP 4 it passes objects by
> value
> > which means when you do
> >
> > $var = new obj();
> > $var 1 = $var;
> >
> > when it assigns var 1 it actually copies the entire $var object, if
> you were
> > to use
> >
> > $var = new obj();
> > $var 1 = &$var;
> >
> > it would assign the reference rather than copy the whole object.
> >
>
> I understand the use of the & in your example, but in your example
> you're not using the & in the = &new line but the one below.
>
> I still don't understand when I should use it and when I shouldn't in
> creating new objects.
>
> Thanks,
>
> Jake.
>
> --
> PHP-GTK General Mailing List (http://gtk.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>