From:             msm at manley dot org
Operating system: Linux, FreeBSD
PHP version:      5.0.0
PHP Bug Type:     Unknown/Other Function
Bug description:  extract(array, EXTR_REFS) fails if array has more than one referring 
symbol

Description:
------------
Is there an issue with extract() using EXTR_REFS when more than one symbol
points to an array variable?

EXTR_REF "extracts variables as references. This effectively means that
the values of the imported variables are still referencing the values of
the var_array parameter." (from
http://us2.php.net/manual/en/function.extract.php)

>From some experiments, I think that this function has issues when you pass
it an array that has been given a reference or pass in a reference to an
array itself. 

It three of the four testcases shown below, it would appear that the
extracted variable $foo is NOT actually a reference into $array['foo']
after the extract() call.

PHP does lazy copies on arrays. Does modifying an array via a reference to
one of the array's members not trigger the lazy copy? This is not the bug
(and makes sense to me), though it certainly added to the confusion trying
to figure out what was happenning here.

The testcases return the same results under PHP 4.3.4, PHP 4.3.8 and PHP
5.0.0 on all the FreeBSD, Linux and Windows systems I have access to.

Reproduce code:
---------------
I describe four testcases and their output at
http://www.sitepoint.com/forums/showthread.php?p=1329965

Sorry, the testcases are longer than 20 lines, all total. In summary:

1) Copy array by reference  -- $array_b =& $array_a -- and then
extract(array, EXTR_REFS) from each.

2) Copy array by value -- $array_b = $array_a -- and then extract(array,
EXTR_REFS) from each.

3) Copy array by reference, then modify a value in the array, then
extract(array, EXTR_REFS) from each.

4) Copy array by value, then modify a value in the array (triggering the
lazy copy), then extract(array, EXTR_REFS) from each.

Expected result:
----------------
In each testcase, given an array ('foo' => 'value') I expect to see a
variable $foo that is a reference to $array['foo'] and when I change
$foo's value, the value of $array['foo'] should change accordingly.

Actual result:
--------------
Is the first three testcases $foo appears not to be a reference to
$array_a['foo'] or $array_b['foo']. 

In the fourth testcase, extract(array, EXTR_REFS) performs as expected. 

-- 
Edit bug report at http://bugs.php.net/?id=29493&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=29493&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=29493&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=29493&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=29493&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=29493&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=29493&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=29493&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=29493&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=29493&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=29493&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=29493&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=29493&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29493&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=29493&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=29493&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=29493&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29493&r=float

Reply via email to