#37825 [Opn->Bgs]: swtich case structure faulty string usage
ID: 37825
Updated by: mike@php.net
Reported By: michael dot nm at mail dot dk
-Status: Open
+Status: Bogus
Bug Type: Unknown/Other Function
Operating System: windows web server 2003
PHP Version: 5.1.4
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
There's no or-operator in a case statement.
Your expression actually evaluates to TRUE.
Previous Comments:
------------------------------------------------------------------------
[2006-06-16 10:27:59] michael dot nm at mail dot dk
Description:
------------
When using a variable og type String, the switch structure behaives
odd.
Reproduce code:
---------------
<?php
$modes = array("byId", "byName", "asSelect", "", null,
"as", "Id",
"Name", "Select");
print "<pre>";
print_r($modes);
print "</pre>";
foreach($modes as $mode) {
print $mode;
switch($mode) {
case "case1":
print "<div>case1 => uses ".$mode."</div>";
break;
case "case2" || "case3":
print "<div>case2 or case3 => uses ".$mode."</div>";
break;
default:
print "<div>default => cannot use ".$mode."</div>";
}
}
?>
Expected result:
----------------
Array
(
[0] => byId
[1] => byName
[2] => asSelect
[3] =>
[4] =>
[5] => as
[6] => Id
[7] => Name
[8] => Select
)
byId
default => cannot use
byName
default => cannot use
asSelect
default => cannot use
("" and null)
default => cannot use
default => cannot use
as
default => cannot use
Id
default => cannot use
Name
default => cannot use
Select
default => cannot use
Actual result:
--------------
Array
(
[0] => byId
[1] => byName
[2] => asSelect
[3] =>
[4] =>
[5] => as
[6] => Id
[7] => Name
[8] => Select
)
byId
case2 or case3 => uses byId
byName
case2 or case3 => uses byName
asSelect
case2 or case3 => uses asSelect
default => cannot use
default => cannot use
as
case2 or case3 => uses as
Id
case2 or case3 => uses Id
Name
case2 or case3 => uses Name
Select
case2 or case3 => uses Select
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=37825&edit=1
Thread (2 messages)