This is a pretty well known issue indeed. I should have read the archive carefully.
Related reports: http://bugs.php.net/bug.php?id=6417 http://bugs.php.net/bug.php?id=7412 http://bugs.php.net/bug.php?id=7515 http://bugs.php.net/bug.php?id=15025 Moriyoshi Moriyoshi Koizumi <[EMAIL PROTECTED]> wrote: > It would be easy to resolve this problem if we were allowed to break > backwards compatibilities, as long as the results of following script can > be said to be expected. > > <?php > $foo = array(1, 2, 3); > $bar = array(); > > $i = count($foo); > while (--$i >= 0) { > $bar[$i] = &$foo[$i]; > } > > $foo_ref = &$foo; > $bar_ref = &$bar; > $foo_copy = $foo; > $bar_copy = $bar; > > $foo_copy[1] = '?'; > > echo 'foo: '; debug_zval_dump($foo); > echo 'foo_ref: '; debug_zval_dump($foo_ref); > echo 'foo_copy: '; debug_zval_dump($foo_copy); > echo 'bar: '; debug_zval_dump($bar); > echo 'bar_ref: '; debug_zval_dump($bar_ref); > echo 'bar_copy: '; debug_zval_dump($bar_copy); > ?> > > Is this a kind of "Won't fix" thing? > > Moriyoshi > > [EMAIL PROTECTED] wrote: > > > ID: 20993 > > Updated by: [EMAIL PROTECTED] > > Reported By: [EMAIL PROTECTED] > > Status: Verified > > Bug Type: Variables related > > Operating System: Any > > PHP Version: 4.0CVS-2002-12-13 > > New Comment: > > > > Verified with 4.2.3 > > > > > > > > Previous Comments: > > ------------------------------------------------------------------------ > > > > [2002-12-13 12:42:22] [EMAIL PROTECTED] > > > > Verified and added testcase to CVS > > > > ------------------------------------------------------------------------ > > > > [2002-12-13 12:01:33] [EMAIL PROTECTED] > > > > I create an array an then a reference to an element of that array. > > Then the array is passed to a function (by value!) which changes the > > value of the element. > > After that, the global array has also another value. > > > > I would expect this behaviour if I passed the array by reference but I > > do not. > > > > <?php > > > > $array = array(1); > > > > $reference =& $array[0]; > > > > echo $array[0], '<br>'; > > theFunction($array); > > > > echo $array[0], '<br>'; > > > > function theFunction($array) { > > $array[0] = 2; > > } > > > > ?> > > > > ------------------------------------------------------------------------ > > > > [2002-12-13 12:00:37] [EMAIL PROTECTED] > > > > I create an array an then a reference to an element of that array. > > Then the array is passed to a function (by value!) which changes the > > value of the element. > > After that, the global array has also another value. > > > > I would expect this behaviour if I passed the array by reference but I > > did not. > > > > <?php > > > > $array = array(1); > > > > $reference =& $array[0]; > > > > echo $array[0], '<br>'; > > theFunction($array); > > > > echo $array[0], '<br>'; > > > > function theFunction($array) { > > $array[0] = 2; > > } > > > > ?> > > > > ------------------------------------------------------------------------ > > > > > > -- > > Edit this bug report at http://bugs.php.net/?id=20993&edit=1 > > > > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php