From:             twonests at yahoo dot com
Operating system: linux, centos 5.0
PHP version:      5.2.6
PHP Bug Type:     Arrays related
Bug description:  After a array key is referenced in a class variable, the 
array can't be copied.

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 bug report at http://bugs.php.net/?id=46461&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=46461&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=46461&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=46461&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=46461&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=46461&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=46461&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=46461&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=46461&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=46461&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=46461&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=46461&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=46461&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=46461&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=46461&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=46461&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=46461&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=46461&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=46461&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=46461&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=46461&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=46461&r=mysqlcfg

Reply via email to