php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34425 switch/case - number/string
Submitted: 2005-09-08 12:15 UTC Modified: 2005-09-08 12:51 UTC
From: htht at mail dot bg Assigned:
Status: Not a bug Package: PHP options/info functions
PHP Version: 4.4.0 OS: Debian, Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
10 + 11 = ?
Subscribe to this entry?

 
 [2005-09-08 12:15 UTC] htht at mail dot bg
Description:
------------
There is problem with switch/case settlement, when the argument is number an the cases are strings; 

Reproduce code:
---------------
$do = 0;
switch ($do)
{
	case 'add':
		print 'we add';
		break;
	case 'upd':
		print 'we update';
		break;
	default: // default display only
		print 'we only display';
		break;
}

Expected result:
----------------
we only display

Actual result:
--------------
we add

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-08 12:51 UTC] sniper@php.net
switch..case is same as if ($do == 'add'). 
Cast the value to string first and you get expected result.
If you had used integers in cases, you should cast to int.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 28 02:01:31 2024 UTC