ID: 37046
Updated by: [EMAIL PROTECTED]
Reported By: karoly at negyesi dot net
-Status: Assigned
+Status: Closed
Bug Type: Scripting Engine problem
Operating System: Linux
PHP Version: 4CVS-2006-04-12
Assigned To: dmitry
New Comment:
Fixed in PHP_4_4 too.
Previous Comments:
------------------------------------------------------------------------
[2006-04-12 21:57:06] [EMAIL PROTECTED]
Dmitry, please also fix this in PHP 4.4.
------------------------------------------------------------------------
[2006-04-12 14:07:26] karoly at negyesi dot net
Please fix in 4.x, too. Thanks.
------------------------------------------------------------------------
[2006-04-12 11:38:58] [EMAIL PROTECTED]
Fixed in CVS HEAD and PHP_5_1.
------------------------------------------------------------------------
[2006-04-12 10:35:21] [EMAIL PROTECTED]
The simplified example:
Reproduce code:
---------------
<?php
function s() {
static $storage = array(array('x', 'y'));
return $storage[0];
}
foreach (s('a') as $k => $function) {
echo "op1 $k\n";
if ($k == 0) {
foreach (s('a') as $k => $function) {
echo "op2 $k\n";
}
}
}
?>
Expected result:
----------------
op1 0
op2 0
op2 1
op1 1
Actual result:
--------------
op1 0
op2 0
op2 1
The bug is similar to bug #35106 (nested foreach fails when array
variable has a reference), but has different reason.
------------------------------------------------------------------------
[2006-04-12 00:08:05] karoly at negyesi dot net
I thought best is if I provide one script...
<?php
function s($key) {
static $storage = array('a' => array('x', 'y'));
return $storage[$key];
}
function s1($key) {
static $storage = array('a' => array('x', 'y'));
return (array)$storage[$key];
}
function s2() {
static $storage = array('x', 'y');
return $storage;
}
function invoke($op, $st) {
foreach ($st('a') as $k => $function) {
echo "$op $k\n";
$function($op, $st);
}
}
function x($op, $st) {
if ($op == 'op1') invoke('op2', $st);
}
function y() {
}
invoke('op1', 's');
echo "\n";
invoke('op1', 's1');
echo "\n";
invoke('op1', 's2');
?>
You get
op1 0
op2 0
op2 1
op1 0
op2 0
op2 1
op1 1
op1 0
op2 0
op2 1
op1 1
if this is not a bug then why they differ?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/37046
--
Edit this bug report at http://bugs.php.net/?id=37046&edit=1