Bug #17938 Updated: Invalid object copy
| From: | mfischer@php.net | Date: | Mon, 24 Jun 2002 08:18:13 +0000 |
| Subject: | Bug #17938 Updated: Invalid object copy | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-11878@lists.php.net to get a copy of this message | ||
ID: 17938
Updated by: mfischer@php.net
Reported By: jacob@inow8.com
-Status: Open
+Status: Feedback
Bug Type: Class/Object related
Operating System: Window 2000
PHP Version: 4.2.1
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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