ID: 46461
User updated by: user at wanted dot email dot removed
Reported By: user at wanted dot email dot removed
Status: Bogus
Bug Type: Arrays related
Operating System: linux, centos 5.0
PHP Version: 5.2.3
New Comment:
Um how is this "bogus"? Elaborate?
Previous Comments:
------------------------------------------------------------------------
[2008-11-02 01:09:46] [EMAIL PROTECTED]
This is in so many ways bogus..
------------------------------------------------------------------------
[2008-11-01 22:38:43] user at wanted dot email dot removed
Description:
------------
If I make an array, (NOT a class, an array with strings in it), and
then one of the keys of that array is referenced by a class instance's
member variable, then that array key/value can no longer be copied. See
the code, it's small.
We have php 5.2.3. No, sorry, we can't upgrade to check if it's been
fixed. Try running the code, it's small.
Your form did not provide me the option of saying so. (Which I think is
unreasonable.)
Reproduce code:
---------------
class c {
private $ref;
public function setref(&$r) {
$this->ref = &$r;
}
}
$ar = array('a'=>'b');
$c = new c();
$c->setref( $ar['a']);
$copy = $ar;
$copy['a'] = 'x';
print_r($ar);
/*
This will print: Array ( [a] => x )
(Which it shouldn't.)
As a demonstration, try commenting out the line $c->setref( $ar['a']);
You'll get a different result. (Which you shouldn't.)
*/
Expected result:
----------------
Array ( [a] => b )
Notice that the line $copy = $ar; is making a copy, not a reference.
Actual result:
--------------
This will print: Array ( [a] => x )
(Which it shouldn't.)
As a demonstration, try commenting out the line $c->setref( $ar['a']);
You'll get a different result. (Which you shouldn't.)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46461&edit=1