Bug #60000 [Opn->Bgs]: switch with int(0)
| From: | johannes@php.net | Date: | Wed, 29 Jun 2011 12:30:37 +0000 |
| Subject: | Bug #60000 [Opn->Bgs]: switch with int(0) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-161406@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60000&edit=1
ID: 60000
Updated by: johannes@php.net
Reported by: k at twojepc dot pl
Summary: switch with int(0)
-Status: Open
+Status: Bogus
Type: Bug
Package: *Programming Data Structures
Operating System: Debian/Windows
PHP Version: 5.3.6
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Switch does a typeless comparison this is needed so code like
const A = 1;
const B = 2;
switch ($_GET['option']) {
case A: ...
Case B: ...
}
works. We are aware of the "strange" aspects of it ...
Previous Comments:
------------------------------------------------------------------------
[2011-06-28 18:23:01] giorgio dot liscio at email dot it
switch uses the == operator
so bogus
$var = 0;
switch (true)
{
case $var === "abc":
echo "abc";
break;
case $var === "zxc":
echo "zxc";
break;
default:
echo "def";
break;
}
------------------------------------------------------------------------
[2011-06-28 17:35:13] k at twojepc dot pl
Description:
------------
Switch use first case element when we use integer zero value.
Test script:
---------------
<?php
$var=0;
switch ($var)
{
case "abc":
echo "abc";
break;
case "zxc":
echo "zxc";
break;
default:
echo "def";
break;
}
Expected result:
----------------
def
Actual result:
--------------
abc
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60000&edit=1