From:             kosthorst at apobyte dot de
Operating system: Debian Etch
PHP version:      5.2.6
PHP Bug Type:     Variables related
Bug description:  By-value assignment is ignored if that variable contains a 
reference

Description:
------------
I assign something by-reference to a variable. If I assign the same stuff
again to the same variable by-value, this assignment is ignored.

In the reproduce code, $bar first is a reference to $foo. $bar is modified
via array_pop(). This modifies $foo, too.

Then, $foo is assigned to $bar by-value. Again, $bar is modified via
array_pop(). And again, $foo is modified too, which should not happen,
because $bar should not be a reference to $foo any more.

An

   unset($bar);

right before the second assignment fixes the issue.

Reproduce code:
---------------
$foo = array(1, 2, 3, 4, 5);
$bar =& $foo;
array_pop($bar);
var_dump($foo);
$bar = $foo;
array_pop($bar);
var_dump($foo);

Expected result:
----------------
array(4) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
}
array(4) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
}

Actual result:
--------------
array(4) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
}
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}

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

Reply via email to