ID:               44181
 User updated by:  robin_fernandes at uk dot ibm dot com
 Reported By:      robin_fernandes at uk dot ibm dot com
 Status:           Open
 Bug Type:         Arrays related
 Operating System: Windows
 PHP Version:      5.2CVS-2008-02-20 (snap)
 New Comment:

I think this is because $a is passed by value, and the call to
SEPARATE_ZVAL_TO_MAKE_IS_REF(entry) below splits the array element from
the original array.

The reference is therefore created to the element of the argument array
which, after the split, is not the same as the element of the original
array.

>From array.c:
...
if (zend_u_hash_find(EG(active_symbol_table), Z_TYPE(final_name),
Z_UNIVAL(final_name), Z_UNILEN(final_name) + 1, (void **) &orig_var) ==
SUCCESS) {
  SEPARATE_ZVAL_TO_MAKE_IS_REF(entry);    // <-- Split! entry no longer
refers to element of $a.
  zval_add_ref(entry);
  zval_ptr_dtor(orig_var);
  *orig_var = *entry;
} else {
...

I believe the root cause for this bug is the same as bug
http://bugs.php.net/44182.

I have submitted a patch for that bug which fixes this one too.


Previous Comments:
------------------------------------------------------------------------

[2008-02-20 09:25:43] robin_fernandes at uk dot ibm dot com

Description:
------------
Using extract() with EXTR_OVERWRITE|EXTR_REFS does not create
references to the array elements if the following conditions are true:
 - $a is referenced by some other variable (its is_ref flag is true).
 - A variable already exists in the current scope with a name matching
the key.

This is reproducible on 5.2, 5.3 and 6.0 snaps.

Reproduce code:
---------------
<?php
$a = array('foo' => 'original.foo');

$foo = 'test';
$ref = &$a;

extract($a, EXTR_OVERWRITE|EXTR_REFS);
$foo = 'changed.foo';

var_dump($a['foo']); //expecting changed.foo
?>

Expected result:
----------------
string(11) "changed.foo"

Actual result:
--------------
string(12) "original.foo"


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44181&edit=1

Reply via email to