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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 09:01:27 2024 UTC