#17938 [Fbk->Csd]: Invalid object copy

From: Date: Wed, 11 Sep 2002 16:24:50 +0000
Subject: #17938 [Fbk->Csd]: Invalid object copy
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-19125@lists.php.net to get a copy of this message
ID: 17938 Updated by: sniper@php.net Reported By: jacob@inow8.com -Status: Feedback +Status: Closed -Bug Type: Class/Object related +Bug Type: Zend Engine 2 problem Operating System: Window 2000 PHP Version: 4.2.1 New Comment: This bug has been fixed in CVS. In case this was a PHP problem, snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. In case this was a documentation problem, the fix will show up soon at http://www.php.net/manual/. In case this was a PHP.net website problem, the change will show up on the PHP.net site and on the mirror sites in short time. Thank you for the report, and for helping us make PHP better. ZE2 thing.. Previous Comments: ------------------------------------------------------------------------ [2002-06-24 04:18:12] mfischer@php.net Please test http://www.php.net/distributions/php-4.3.0-dev-zend2-alpha1pl1.tar.gz , I'm pretty sure this sort of behaviour is fixed in ZE2. ------------------------------------------------------------------------ [2002-06-24 04:06:32] jacob@inow8.com The below example shows how $a is copyed (=) into $b but dosent make a "copy" or dos it? Its about the prob properti, i asign an object "Obj" to $a->prob, and sets a new properti, $a->prob->p1, then i run the method $a->prob->PrintObj(), and copyes $a it into $b, and asign $b->prob->p2 to the cloned version of $b, and $a->prob->p3 to the original version of $a. If this sould be right then $a->prob will have p1 and p3, and $b->prob will have p1 and p2... but because of the PrintObj method thats not the case... and it has nothing to do with the name and action of the method! class Obj { function Obj() { $this->name = 'a'; } function PrintObj() { echo 'Printing...'; } } $a = new Obj(); $a->prob = new Obj(); $a->prob->p1 = 'test'; //This is the problem... running a method (any method) before copying! //Causing a "reference" only to the "prob" properti in the copy version. $a->prob->PrintObj(); $b = $a; $b->prob->p2 = 'test'; $a->prob->p3 = 'test'; print_r($a); print_r($b); /* Printing...obj Object ( [name] => a [prob] => obj Object ( [name] => a [p1] => test [p2] => test [p3] => test ) ) obj Object ( [name] => b [prob] => obj Object ( [name] => a [p1] => test [p2] => test [p3] => test ) ) */ //--------------------------------------------------- //Now lets try without the method!!! //--------------------------------------------------- $a = new Obj(); $a->prob = new Obj(); $a->prob->p1 = 'test'; //This code dos what i whant, because i dont execute the PrintObj method???? $b = $a; $b->prob->p2 = 'test'; $a->prob->p3 = 'test'; print_r($a); print_r($b); /* obj Object ( [name] => a [prob] => obj Object ( [name] => a [p1] => test [p3] => test ) ) obj Object ( [name] => b [prob] => obj Object ( [name] => a [p1] => test [p2] => test ) } */ Your sincerely Jacob Lindborg ------------------------------------------------------------------------ [2002-06-24 04:04:01] jacob@inow8.com The below example shows how $a is copyed (=) into $b but dosent make a "copy" or dos it? Its about the prob properti, i asign an object "Obj" to $a->prob, and sets a new properti, $a->prob->p1, then i run the method $a->prob->PrintObj(), and copyes $a it into $b, and asign $b->prob->p2 to the cloned version of $b, and $a->prob->p3 to the original version of $a. If this sould be right then $a->prob will have p1 and p3, and $b->prob will have p1 and p2... but because of the PrintObj method thats not the case... and it has nothing to do with the name and action of the method! class Obj { function Obj() { $this->name = 'a'; } function PrintObj() { echo 'Printing...'; } } $a = new Obj(); $a->prob = new Obj(); $a->prob->p1 = 'test'; //This is the problem... running a method (any method) before copying! //Causing a "reference" only to the "prob" properti in the copy version. $a->prob->PrintObj(); $b = $a; $b->prob->p2 = 'test'; $a->prob->p3 = 'test'; print_r($a); print_r($b); /* Printing...obj Object ( [name] => a [prob] => obj Object ( [name] => a [p1] => test [p2] => test [p3] => test ) ) obj Object ( [name] => b [prob] => obj Object ( [name] => a [p1] => test [p2] => test [p3] => test ) ) */ $a = new Obj(); $a->prob = new Obj(); $a->prob->p1 = 'test'; //This code dos what i whant, because i dont execute the PrintObj method???? $b = $a; $b->prob->p2 = 'test'; $a->prob->p3 = 'test'; print_r($a); print_r($b); /* obj Object ( [name] => a [prob] => obj Object ( [name] => a [p1] => test [p3] => test ) ) obj Object ( [name] => b [prob] => obj Object ( [name] => a [p1] => test [p2] => test ) } */ Your sincerely Jacob Lindborg ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=17938&edit=1

« previous php.bugs (#19125) next »