Mantis - Quercus
Viewing Issue Advanced Details
3199 minor always 12-28-08 13:37 12-29-08 10:33
koreth  
ferg  
normal  
closed 4.0.0  
fixed  
none    
none 4.0.0  
0003199: Static array passed as argument to function in another file loses copy-on-write in compiled mode
lookup.php:

<?php
function lookup($arr, $idx) {
  return $arr[$idx];
}


test.php:

<?php
include_once 'lookup.php';

class Foo {
  public $attrs = array();
  public function gimme() {
    static $val = array('x' => array());
    $this->attrs['x'] = lookup($val, 'x');
  }
}

$foo = new Foo();
$foo->gimme();
print "Before: ";
print_r($foo->attrs);
print "
\n";

$foo->attrs['x'][] = 'z';

$foo = new Foo();
$foo->gimme();
print "After: ";
print_r($foo->attrs);


Regular PHP, and Quercus in interpreted mode, prints

Before: Array ( [x] => Array ( ) )
After: Array ( [x] => Array ( ) )

Quercus in compiled mode prints

Before: Array ( [x] => Array ( ) )
After: Array ( [x] => Array ( [0] => z ) )

If you move the function to the same source file as the test, the problem goes away.

Notes
(0003681)
ferg   
12-29-08 10:33   
php/347b