ID:               33368
 Updated by:       [EMAIL PROTECTED]
 Reported By:      drphilosopher at yahoo dot com
-Status:           Open
+Status:           Feedback
 Bug Type:         Arrays related
 Operating System: Windows XP Service Patch 2
 PHP Version:      5.0.3
 New Comment:

Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip




Previous Comments:
------------------------------------------------------------------------

[2005-06-16 20:35:05] drphilosopher at yahoo dot com

Description:
------------
The string, '0', is not handled correctly 
in a foreach loop (and possibly elsewhere).

The first loop executes correctly.  The 
second and third loops perform incorrect
comparisons.  

In loops two and three, '0' == 'NOLIMIT'
evaluates to true when it should be false.


Reproduce code:
---------------
$arr = array('0' => '$0',
             '1000' => '$1,000', 
             '2000' => '$2,000', 
             '3000' => '$3,000', 
             'NOLIMIT' => 'NO LIMIT');
foreach ($arr as $key => $value)
{
    echo "$key : $value $hi\n";
}
echo "\n";
foreach ($arr as $key => $value)
{
    if ($key == 'NOLIMIT') { continue; }
    echo "$key : $value $hi\n";
}
echo "\n";
foreach ($arr as $key => $value)
{
    $hi = ($key == 'NOLIMIT' ? 'hi' : '');
    echo "$key : $value      $hi\n";
}

Expected result:
----------------
0 : $0 
1000 : $1,000 
2000 : $2,000 
3000 : $3,000 
NOLIMIT : NO LIMIT 

0 : $0 
1000 : $1,000 
2000 : $2,000 
3000 : $3,000 

0 : $0
1000 : $1,000      
2000 : $2,000      
3000 : $3,000      
NOLIMIT : NO LIMIT      hi

Actual result:
--------------
0 : $0 
1000 : $1,000 
2000 : $2,000 
3000 : $3,000 
NOLIMIT : NO LIMIT 

1000 : $1,000 
2000 : $2,000 
3000 : $3,000 

0 : $0      hi
1000 : $1,000      
2000 : $2,000      
3000 : $3,000      
NOLIMIT : NO LIMIT      hi

I am using PHP 5.03 and Apache 2.0.53 on Windows XP, service patch 2.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=33368&edit=1

Reply via email to