--- Robert Cummings <[EMAIL PROTECTED]> wrote:
> brad lafountain wrote:
> > 
> > > As far as references go... I believe when you copy an object it is a
> > > shallow copy, in otherwords, the object is copied, but not its members.
> > > This behaviour is preferrable as far as I'm concerned. If you want a
> > > deep copy try doing the following:
> > >
> > > $foo = new foo();
> > > $fee = unserialize( serialize( $foo ) );
> > >
> > > That should provide a nice quick, clean solution for what you want while
> > > not incurring the overhead most programmers would rather skip on every
> > > object copy.
> > 
> >  I shouldn't have to $fee = unserialize( serialize( $foo ) ) everytime i
> want
> > to get a copy of an object when the engine says it copys. That is FAR from
> > 'clean'. A possible soultion for this to get around the speed vs
> functionality.
> > The engine could keep track of a copy and when and only when a member gets
> > change that is when it should make the copy of the member objects. So you
> get
> > the speed but it is transparent to the user.
> 
> And I shouldn't have to wait for all the housekeeping code to do it's thing
> to keep track of whether I'm changing a member variable or not. So I get the
> speed don't need to do $foo = &$fee every time I want a change the member 
> variables of the original object. The engine says it copies... it doesn't say
> it DEEP copies. Please understand the difference.

 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

> 
> Cheers,
> Rob.
> -- 
> .-----------------.
> | Robert Cummings |
> :-----------------`----------------------------.
> | Webdeployer - Chief PHP and Java Programmer  |
> :----------------------------------------------:
> | Mail  : mailto:[EMAIL PROTECTED] |
> | Phone : (613) 731-4046 x.109                 |
> :----------------------------------------------:
> | Website : http://www.webmotion.com           |
> | Fax     : (613) 260-9545                     |
> `----------------------------------------------'


__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to