Bug #69558 [NEW]: switch statement output unexpected
| From: | stephane at winnepenninckx dot com | Date: | Fri, 01 May 2015 15:37:59 +0000 |
| Subject: | Bug #69558 [NEW]: switch statement output unexpected | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-192436@lists.php.net to get a copy of this message | ||
From: stephane at winnepenninckx dot com
Operating system: mac os x 10.10
PHP version: 5.6.8
Package: Scripting Engine problem
Bug Type: Bug
Bug description:switch statement output unexpected
Description:
------------
the case $i < 1 down not occur for $i = 0, the script goes to the
default case:
-----------------
0 : Oops
-----------------
If you delete the default case :
-----------------
0 : quite bad!
-----------------
I try with the for loop modified :
for ($i = 10.1; $i >= 0; --$i)
then the case $i<1 occurs :
-----------------
0.1 : really!!
-----------------
It looks like there is a problem with the value 0 when comparing to 1
also in older versions of PHP like 5.5
Test script:
---------------
$sep = PHP_EOL.'-----------------'.PHP_EOL;
echo 'switch demo';
echo $sep;
for ($i = 10; $i >= 0; --$i) {
switch($i) {
case $i < 1 :
$msg = 'really!!';
break;
case $i < 3 :
$msg = 'quite bad!';
break;
case $i < 5 :
$msg = 'pay attention!';
break;
case $i <= 9 :
$msg = 'quite good';
break;
case $i <= 10 :
$msg = 'congrat';
break;
default:
$msg = 'Oops';
break;
}
echo $i . ' : '.$msg.$sep;
}
Expected result:
----------------
when $i = 0 the $msg should be 'really!!' not 'Oops':
-----------------
0 : really!!
-----------------
--
Edit bug report at https://bugs.php.net/bug.php?id=69558&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69558&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69558&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69558&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69558&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69558&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69558&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69558&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69558&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69558&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69558&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69558&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69558&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69558&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69558&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69558&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69558&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69558&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69558&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69558&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69558&r=mysqlcfg