From: r at dumb dot ro
Operating system: all
PHP version: 5.2.9
PHP Bug Type: *General Issues
Bug description: array_clone - would also clone referenced objects
Description:
------------
When you pass an array of objects to a function (not by reference) and you
modfiy one of the objects in the array, the main array (the referenced
objects) will be modified. This wasn't a problem until objects got passed
by reference by default.
Reproduce code:
---------------
$class A
{
}
$a = new A();
$a->x = 10;
$arr = array($a);
function foo($arr)
{
$arr[0]->x = 1;
}
foo($arr);
print_r($arr);
Expected result:
----------------
the expected result would be 10
Actual result:
--------------
since the array is internally using references for the stored objects the
result will be 1.
to fix this I wrote a function that clones the array properly and I'm
calling the function like this:
foo(array_clone($arr));
--
Edit bug report at http://bugs.php.net/?id=47967&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=47967&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=47967&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=47967&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=47967&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=47967&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=47967&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=47967&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=47967&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=47967&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=47967&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=47967&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=47967&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=47967&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=47967&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47967&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47967&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=47967&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=47967&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=47967&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=47967&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=47967&r=mysqlcfg