ID: 31402
Updated by: [EMAIL PROTECTED]
Reported By: otto at efficiency-online dot nl
-Status: Verified
+Status: Closed
Bug Type: Scripting Engine problem
Operating System: *
PHP Version: 5CVS, 4CVS (2005-01-18)
-Assigned To:
+Assigned To: dmitry
New Comment:
Fixed in PHP_4_4.
It was already fixed in HEAD and PHP_5_0.
Previous Comments:
------------------------------------------------------------------------
[2005-01-04 09:22:55] otto at efficiency-online dot nl
Description:
------------
An object having a field initialized to a element of an array in the
same object is transformed into a reference after unserializing. I had
a session object exposing this problem and managed to create a code
snippet exposing the problem. After the assignment to the field $y->B,
the array should not have changed, but it is changed.
It looks like $y->B has become a reference to $y->A[1] after the
unserialize call. This is a regression wrt to 4.3.9 and might be
related to bug Bug #31213.
Reproduce code:
---------------
<?php
class X {
var $i;
function X($i) {
$this->i = $i;
}
}
class Y {
var $A = array();
var $B;
function x() {
$this->A[1] = new X(1);
$this->A[2] = new X(2);
$this->B = $this->A[1];
}
}
$x = new Y();
$x->x();
echo "original object:\n";
print_r($x);
$ser = serialize($x);
$y = unserialize($ser);
echo "after unserialize:\n";
print_r($y);
$y->B = $y->A[2];
echo "after assignment:\n";
print_r($y);
?>
Expected result:
----------------
// result with 4.3.9
original object:
y Object
(
[A] => Array
(
[1] => x Object
(
[i] => 1
)
[2] => x Object
(
[i] => 2
)
)
[B] => x Object
(
[i] => 1
)
)
after unserialize:
y Object
(
[A] => Array
(
[1] => x Object
(
[i] => 1
)
[2] => x Object
(
[i] => 2
)
)
[B] => x Object
(
[i] => 1
)
)
after assignment:
y Object
(
[A] => Array
(
[1] => x Object
(
[i] => 1
)
[2] => x Object
(
[i] => 2
)
)
[B] => x Object
(
[i] => 2
)
)
Actual result:
--------------
// result with 4.3.10
y Object
(
[A] => Array
(
[1] => x Object
(
[i] => 1
)
[2] => x Object
(
[i] => 2
)
)
[B] => x Object
(
[i] => 1
)
)
after unserialize:
y Object
(
[A] => Array
(
[1] => x Object
(
[i] => 1
)
[2] => x Object
(
[i] => 2
)
)
[B] => x Object
(
[i] => 1
)
)
after assignment:
y Object
(
[A] => Array
(
[1] => x Object
(
[i] => 2
)
[2] => x Object
(
[i] => 2
)
)
[B] => x Object
(
[i] => 2
)
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=31402&edit=1