#25566 [Opn]: switch expressions seem to get cast to specific type.
| From: | Jared dot Williams1 at ntlworld dot com | Date: | Tue, 16 Sep 2003 22:47:45 +0000 |
| Subject: | #25566 [Opn]: switch expressions seem to get cast to specific type. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-47666@lists.php.net to get a copy of this message | ||
ID: 25566
User updated by: Jared dot Williams1 at ntlworld dot com
Reported By: Jared dot Williams1 at ntlworld dot com
Status: Open
Bug Type: Scripting Engine problem
PHP Version: 4.3.3
New Comment:
"The first 5 array" should read "The first 4 array"
Previous Comments:
------------------------------------------------------------------------
[2003-09-16 18:41:54] Jared dot Williams1 at ntlworld dot com
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 this bug report at http://bugs.php.net/?id=25566&edit=1