php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35188 switch always picks case 0
Submitted: 2005-11-11 02:47 UTC Modified: 2005-11-11 07:55 UTC
From: daniel at assertio dot es Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.5 OS: Win XP
Private report: No CVE-ID: None
 [2005-11-11 02:47 UTC] daniel at assertio dot es
Description:
------------
If a switch case is 0 and the variable value evaluated in the switch is a string, that case is picked.

Reproduce code:
---------------
$var = "hello";
switch($var){
	case 0: 
		echo "var is 0";
		break;
	default:
		echo "default!";
}

Expected result:
----------------
default!

Actual result:
--------------
var is 0

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-11 03:56 UTC] sniper@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.


 [2005-11-11 07:55 UTC] daniel at assertio dot es
Found it explained in http://es.php.net/manual/en/language.operators.comparison.php

" If you compare an integer with a string, the string is converted to a number."

hth...
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 19:01:36 2025 UTC