Mantis - Quercus
Viewing Issue Advanced Details
3130 minor always 12-06-08 12:51 12-10-08 09:15
koreth  
nam  
normal  
closed 3.2.1  
fixed  
none    
none 4.0.0  
0003130: array_fill() should copy, not reference, values
Similar to bug 2930:

<?php
$x = array_fill(0, 2, array());
$x[0][] = 'foo';
print_r($x);

This prints

Array
(
    [0] => Array
        (
            [0] => foo
        )

    [1] => Array
        (
            [0] => foo
        )

)

The second child array should be empty. The fix is similar to the previous bug's:

--- a/modules/quercus/src/com/caucho/quercus/lib/ArrayModule.java
+++ b/modules/quercus/src/com/caucho/quercus/lib/ArrayModule.java
@@ -537,7 +537,7 @@ public class ArrayModule
     ArrayValue array = new ArrayValueImpl();
 
     for (long k = start; k < num + start; k++)
- array.put(LongValue.create(k), value);
+ array.put(LongValue.create(k), value.copy());
 
     return array;
   }

Notes
(0003592)
nam   
12-10-08 09:15   
php/171a