#32840 [NEW]: returning member-variables causes unwanted return by reference
| From: | wagner at bonn dot edu | Date: | Tue, 26 Apr 2005 12:37:53 +0000 |
| Subject: | #32840 [NEW]: returning member-variables causes unwanted return by reference | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-78208@lists.php.net to get a copy of this message | ||
From: wagner at bonn dot edu
Operating system: gentoo linux
PHP version: 5.0.4
PHP Bug Type: Scripting Engine problem
Bug description: returning member-variables causes unwanted return by reference
Description:
------------
Returning a value of an array or a member-variable causes
the return to be by reference. This also happens in PHP
4.3.x
Related to http://bugs.php.net/bug.php?id=32789
which
seems bogusified beyond repair.
Reproduce code:
---------------
function incr(&$int) {
return $int++;
}
function f() {
static $v;
if (!$v)
$v = 1;
return($v);
}
function f2() {
static $v;
if (!$v) {
$v = array();
$v[0] = 1;
}
return($v[0]);
}
echo "f1: ".incr(f()).incr(f())."\n";
echo "f2: ".incr(f2()).incr(f2())."\n";
Expected result:
----------------
f1: 11
f2: 12
Same behaviour for both functions.
Actual result:
--------------
f1: 11
f2: 12
f2 inexplicably returns a reference.
The manual states that for this to happen, it should be
necessary to actually use a & in front of the definition
of the returning function:
http://de2.php.net/manual/en/language.references.return.php
"... you have to use & in both places - to indicate that
you return by-reference, not a copy as usual, and to
indicate that reference binding, rather than usual
assignment, should be done ..."
--
Edit bug report at http://bugs.php.net/?id=32840&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=32840&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=32840&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=32840&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=32840&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=32840&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=32840&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=32840&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=32840&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=32840&r=support
Expected behavior: http://bugs.php.net/fix.php?id=32840&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=32840&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=32840&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=32840&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=32840&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=32840&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=32840&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=32840&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=32840&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=32840&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=32840&r=mysqlcfg