Mantis - Quercus
Viewing Issue Advanced Details
2930 minor always 09-12-08 15:42 09-12-08 17:25
koreth  
nam  
normal  
closed 3.2.1  
fixed  
none    
none 3.2.1  
0002930: array_fill_keys() needs to copy, not reference, values
<?php
$foo = array_fill_keys(array('a','b'), array());
$foo['a'][] = 'bar';
print $foo['b'][0];

In Vanilla PHP, this doesn't print anything since $foo['b'] is empty. In Quercus it prints 'bar' because $foo['b'] refers to the same underlying array as $foo['a'].
Patch that seems to fix it:

--- a/modules/quercus/src/com/caucho/quercus/lib/ArrayModule.java
+++ b/modules/quercus/src/com/caucho/quercus/lib/ArrayModule.java
@@ -1998,7 +1998,7 @@
     Iterator<Value> iter = keyArray.getValueIterator(env);
     
     while (iter.hasNext()) {
- array.put(iter.next(), value);
+ array.put(iter.next(), value.copy());
     }
     
     return array;

Notes
(0003435)
nam   
09-12-08 17:25   
php/1770

It appears that a couple of other ArrayModule functions may also be affected.