php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41498 switch..case output error
Submitted: 2007-05-25 13:43 UTC Modified: 2007-05-25 16:14 UTC
From: eg dot soft at msa dot hinet dot net Assigned:
Status: Not a bug Package: Output Control
PHP Version: 5.2.2 OS: windows xp
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: eg dot soft at msa dot hinet dot net
New email:
PHP Version: OS:

 

 [2007-05-25 13:43 UTC] eg dot soft at msa dot hinet dot net
Description:
------------
$a = 'aa';
$b = 'bb';
$value = 0;
switch ($value) {
	case $a:
		echo $a."\n"; 
		break;
	case $b:
		echo $b."\n"; 
		break;
	default:	
		echo "default\n";
}
==> output: aa (Why?!)

$a = 'aa';
$b = 'bb';
$value = 0;
switch ($value) {
	case $b:
		echo $b."\n"; 
		break;
	case $a:
		echo $a."\n"; 
		break;
	default:	
		echo "default\n";
}
==> output: bb (Why?!)


Reproduce code:
---------------
$a = 'aa';
$b = 'bb';
$value = 0;
switch ($value) {
	case $a:
		echo $a."\n"; 
		break;
	case $b:
		echo $b."\n"; 
		break;
	default:	
		echo "default\n";
}


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

Actual result:
--------------
aa

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-25 16:12 UTC] crestfresh at gmail dot com
http://www.php.net/manual/en/language.operators.comparison.php

"If you compare an integer with a string, the string is converted to a number. If you compare two numerical strings, they are compared as integers. These rules also apply to the switch statement."
 [2007-05-25 16:14 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon May 12 04:01:29 2025 UTC