Bug #69558 [Opn->Nab]: switch statement output unexpected
| From: | nikic@php.net | Date: | Fri, 01 May 2015 16:24:09 +0000 |
| Subject: | Bug #69558 [Opn->Nab]: switch statement output unexpected | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-192437@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69558&edit=1
ID: 69558
Updated by: nikic@php.net
Reported by: stephane at winnepenninckx dot com
Summary: switch statement output unexpected
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: mac os x 10.10
PHP Version: 5.6.8
Block user comment: N
Private report: N
New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
Previous Comments:
------------------------------------------------------------------------
[2015-05-01 15:37:58] stephane at winnepenninckx dot com
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 this bug report at https://bugs.php.net/bug.php?id=69558&edit=1