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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 13:01:35 2025 UTC