#39949 [NEW]: Returned reference cloned if stored in variable
| From: | ap at tellusion dot com | Date: | Tue, 26 Dec 2006 04:29:13 +0000 |
| Subject: | #39949 [NEW]: Returned reference cloned if stored in variable | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-106876@lists.php.net to get a copy of this message | ||
From: ap at tellusion dot com
Operating system: Linux Red Hat EL
PHP version: 5CVS-2006-12-26 (snap)
PHP Bug Type: Variables related
Bug description: Returned reference cloned if stored in variable
Description:
------------
If a function (or object method) returns a reference (as a return value or
by writing to a reference supplied as a parameter), and the caller saves
that reference in a variable, the object/array/variable that is referenced
is incorrectly cloned.
Interestingly, if the return value is passed directly to 2nd function (or
object method) the bug does not occur, that is, the variable is not cloned
and the reference is passed to 2nd function in-tact.
Reproduce code:
---------------
I have provided two scripts to reproduce the bug. One is a procedural
example (reftest-array2.php) and the other is an OO example
(reftest-object2.php).
They can be downloaded from http://www.tellusion.com/reftest2.tar
ISOLATION
This is potentially related but still separate to bug #39944 (which was
fixed). I have modified two of the scripts I submitted previosuly to
clearly demonstrate the presence of this bug only.
The bug is present in PHP 5.0.4 and all versions of PHP 5.1 & 5.2
including the latest version of 5.2-STABLE.
I havent tested any older versions of PHP.
Expected result:
----------------
### reftest-array2.php ###
arrTheArray = Array
(
[0] => xx1
[1] => xx2
[2] => xx3
)
### reftest-object2.php ###
RefTest::addToArray(): arr = Array
(
[0] => xx1
)
RefTest::addToArray(): arr = Array
(
[0] => xx1
[1] => xx2
)
RefTest::addToArray(): arr = Array
(
[0] => xx1
[1] => xx2
[2] => xx3
)
objRefTest->getArray() = Array
(
[0] => xx1
[1] => xx2
[2] => xx3
)
Actual result:
--------------
### reftest-array2.php ###
arrTheArray = Array
(
[0] => xx3
)
### reftest-object2.php ###
RefTest::addToArray(): arr = Array
(
[0] => xx1
)
RefTest::addToArray(): arr = Array
(
[0] => xx2
)
RefTest::addToArray(): arr = Array
(
[0] => xx3
)
objRefTest->getArray() = Array
(
)
--
Edit bug report at http://bugs.php.net/?id=39949&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39949&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39949&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39949&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=39949&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=39949&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=39949&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=39949&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=39949&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=39949&r=support
Expected behavior: http://bugs.php.net/fix.php?id=39949&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=39949&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=39949&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=39949&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39949&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=39949&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=39949&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=39949&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=39949&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=39949&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=39949&r=mysqlcfg