From: otto at efficiency-online dot nl
Operating system: OpenBSD 3.6
PHP version: 4.3.10
PHP Bug Type: Scripting Engine problem
Bug description: unserialize creates a field containing a reference when it
should not
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 bug report at http://bugs.php.net/?id=31402&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31402&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=31402&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=31402&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31402&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31402&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31402&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31402&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31402&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31402&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31402&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=31402&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=31402&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31402&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31402&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31402&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31402&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31402&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31402&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=31402&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31402&r=mysqlcfg