From:             Jared dot Williams1 at ntlworld dot com
Operating system: 
PHP version:      4.3.3
PHP Bug Type:     Scripting Engine problem
Bug description:  switch expressions seem to get cast to specific type.

Description:
------------
Switched expressions seem to be cast to a type before case matching
occurs.

If all case expressions are of the same type, either numeric, or string,
this problem does not arise.

It is not clear why, or really what type the switched expression is cast
to before comparision.





Reproduce code:
---------------
$t = array(0,1,2,3,'*','+','a', 'b')
foreach($t as $v)
        switch ($v)
        {
                case 0: echo('0'); break;
                case 1: echo('1'); break;
                case 2: echo('2'); break;
                case 3: echo('3'); break;
                case '*': echo('*'); break;
                default: echo($v); break;
        }

Expected result:
----------------
0123*+ab


The first 5 array elements are output their respective case statements,
and the latter 3 are handled by the default case.

Actual result:
--------------
01230000 

The first 5 array elements are output their respective case statements,
and the latter 3 are handled the 0 case.


-- 
Edit bug report at http://bugs.php.net/?id=25566&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=25566&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=25566&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=25566&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=25566&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=25566&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=25566&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=25566&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=25566&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=25566&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=25566&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=25566&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25566&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=25566&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=25566&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=25566&r=gnused

Reply via email to