php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45163 switch() statement incorrect
Submitted: 2008-06-04 05:36 UTC Modified: 2008-06-14 09:26 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: waps at pisem dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.6 OS: Win Vista x32 Business
Private report: No CVE-ID: None
 [2008-06-04 05:36 UTC] waps at pisem dot net
Description:
------------
SWITCH statement incorrect work from data types. In exemple I write code.

Reproduce code:
---------------
$strCode = 0;
switch( $strFileType )		
{
	case 'jpg':
	case 'jpeg':
		echo 'point 0';
		break;
	case 'gif':
		echo 'point 1';
		break;
	default:
		echo 'point 3';
}

Expected result:
----------------
echo string "point 0"

Actual result:
--------------
I have to view "point 3", but no "point 0"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-05 18:10 UTC] jani@php.net
Please provide a script that has some possibility to work, logically too. A proper reproducing script starts with <?php and ends with ?>, is no longer than 20 lines and is self-contained in every way.
 [2008-06-13 19:12 UTC] waps at pisem dot net
Old excampe incorrected!
This excemple correct:

$strCode = 0;
switch( $strCode )		
{
	case 'jpg':
	case 'jpeg':
		echo 'point 0';
		break;
	case 'gif':
		echo 'point 1';
		break;
	default:
		echo 'point 3';
}
 [2008-06-13 19:17 UTC] waps at pisem dot net
<?php
$strCode = 0;
switch( $strCode )		
{
	case 'jpg':
	case 'jpeg':
		echo 'point 0';
		break;
	case 'gif':
		echo 'point 1';
		break;
	default:
		echo 'point 3';
}
?>
 [2008-06-14 09:26 UTC] scottmac@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

See http://www.php.net/operators.comparison

0 == 'string'

The right hand side is cast to an integer, in this case the right hand side ends up as 0.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 10 12:01:33 2025 UTC