From:             eric at austarmetro dot com dot au
Operating system: Win XP
PHP version:      4.3.3RC1
PHP Bug Type:     Scripting Engine problem
Bug description:  foreach stops with boolen expresion in loop

Description:
------------
The foreach loop exits early and sets the $status variable to "".
The problem is fixed by changing 
$status = $status && status( $b );
to
$status &= status( $b );

Hope this is bogus :)
I have tried this on WinXP PHP4.3.3RC1 and FREEBSD PHP4.3.1 both give the
same result.

Eric


Reproduce code:
---------------
<?
function status( $c ) {
   echo $c;
   if( $c == 'two' )
      return 0;
   return 1;
}

$a = array( 'one ','two ','three ','four ' );
$status = 1;
foreach( $a as $b )
{
 $status = $status &&  status( $b );
}
echo " foreach stopped. Status = ".$status;
if( isset( $status ) )
 echo " set ";
else
 echo "unset";
?>

Expected result:
----------------
onetwothreefour foreach stopped. Status = 0 set

Actual result:
--------------
onetwo foreach stopped. Status = set

-- 
Edit bug report at http://bugs.php.net/?id=24626&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=24626&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=24626&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=24626&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=24626&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=24626&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=24626&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=24626&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=24626&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=24626&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=24626&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=24626&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=24626&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=24626&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=24626&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=24626&r=gnused

Reply via email to