ID: 29155 Comment by: no at spam dot forme Reported By: phpbug at bart dot w-wa dot pl Status: Bogus Bug Type: Variables related Operating System: Linux PHP Version: 4.3.7 New Comment:
you test one integer 0 against a string, which causes php to cast your string into an integer, which results in 0 for the string 'something'. thus, the first case comparison looks like 0 == 'something' <=> 0 == 0 <=> true, the program prints 'something' and breaks the switch. Your result is the expected result. I think this should be more explicitly empathized in the php manual. Previous Comments: ------------------------------------------------------------------------ [2004-07-14 16:49:32] [EMAIL PROTECTED] 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 . ------------------------------------------------------------------------ [2004-07-14 16:46:21] phpbug at bart dot w-wa dot pl Description: ------------ Due to FU typecasting switch produces unexpected results when one of the cases is string, but variable passed to switch is int. Reproduce code: --------------- $x = 0; switch($x) { case 'something': echo 'something'; break; case 0: echo 'zero'; break; default: echo 'something else'; }; Expected result: ---------------- zero Actual result: -------------- something ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29155&edit=1