#23705 [NEW]: Reassigned object-ref params don't propagate back properly.
| From: | joachim at lous dot org | Date: | Mon, 19 May 2003 19:59:47 +0000 |
| Subject: | #23705 [NEW]: Reassigned object-ref params don't propagate back properly. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-39990@lists.php.net to get a copy of this message | ||
From: joachim at lous dot org
Operating system: Windows 2000
PHP version: 4.3.1
PHP Bug Type: Class/Object related
Bug description: Reassigned object-ref params don't propagate back properly.
It doesn't seem to be possible to replace a passed object references with a
different one.
I expected the following code to print "5":
class a{
var $val;
function a($val){ $this->val = $val;}
}
function replace(&$src, &$dest){
$dest =& $src;
}
$src = new a(2);
$dest = new a(1);
replace($src,$dest);
$src->val=5;
echo $dest->val;
In stead it prints "1".
Changing the '=&' to '=', it prints '2', as expected.
Surely this must be a bug? If not, is there really no way to get the
reference across?
I need this for building trees: passing the current node pointer, have the
function change the tree and make the ref point to a new current node. I
can work around it by returning the new reference in stead, but that only
works for one ref.
Using binary installer from website.
--
Edit bug report at http://bugs.php.net/?id=23705&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=23705&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=23705&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=23705&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=23705&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=23705&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=23705&r=support
Expected behavior: http://bugs.php.net/fix.php?id=23705&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=23705&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=23705&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=23705&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=23705&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=23705&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=23705&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=23705&r=gnused