#31402 [Opn->Fbk]: unserialize creates a field containing a reference when it should not
ID: 31402
Updated by: sniper@php.net
Reported By: otto at efficiency-online dot nl
-Status: Open
+Status: Feedback
Bug Type: Scripting Engine problem
Operating System: OpenBSD 3.6
PHP Version: 4.3.10
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php4-STABLE-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php4-win32-STABLE-latest.zip
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
Thread (5 messages)