From:             michael dot nm at mail dot dk
Operating system: windows web server 2003
PHP version:      5.1.4
PHP Bug Type:     Unknown/Other Function
Bug description:  swtich case structure faulty string usage

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 bug report at http://bugs.php.net/?id=37825&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=37825&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=37825&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=37825&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=37825&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=37825&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=37825&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=37825&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=37825&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=37825&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=37825&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=37825&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=37825&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=37825&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=37825&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=37825&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=37825&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=37825&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=37825&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=37825&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=37825&r=mysqlcfg

Reply via email to