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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: htht at mail dot bg
New email:
PHP Version: OS:

 

 [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: Mon May 06 23:01:31 2024 UTC