Re: object refrences (POSSIBLE MAJOR BUG)
| From: | Robert Cummings | Date: | Thu, 11 Apr 2002 18:54:14 +0000 |
| Subject: | Re: object refrences (POSSIBLE MAJOR BUG) | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-82619@lists.php.net to get a copy of this message | ||
My apologies... this examples better clarifies your point and I must admit
that it is rather strange behaviour :) And I think I forgot that PHP does
do deep copies, probably because I'm so used to writing wrapper objects
with references to my real objects so I automate shallow copies.
Cheers,
Rob.
brad lafountain wrote:
>
>
> I do understand the difference... but it also doesn't say it does a shallow
> copy. because it DOES do a deep copy.... run the following code..
>
> <?
> class foo
> {
> function foo()
> {
> $this->bar = new bar();
> }
> }
>
> class bar
> {
> function bar()
> {
> $this->tmp = "bar";
> }
> function do_nothing()
> {
> }
> }
>
> // As you see no shallow copy!!
> $foo = new foo();
> $foo->bar->tmp = "test";
> $foo2 = $foo;
> $foo2->bar->tmp = "foo";
> var_dump($foo);
> var_dump($foo2);
>
> // now....
> $foo->bar->do_nothing();
> $foo3 = $foo;
> $foo3->bar->tmp = "bug";
> var_dump($foo);
> var_dump($foo3);
> ?>
>
> as soon as a function is called from a objects member.. this is where the
> refrence is created!
>
> - Brad
--
.-----------------.
| Robert Cummings |
:-----------------`----------------------------.
| Webdeployer - Chief PHP and Java Programmer |
:----------------------------------------------:
| Mail : mailto:robert.cummings@webmotion.com |
| Phone : (613) 731-4046 x.109 |
:----------------------------------------------:
| Website : http://www.webmotion.com |
| Fax : (613) 260-9545 |
`----------------------------------------------'