Bug #15010 Updated: switch() problem: "+" matches "-"

From: Date: Wed, 23 Jan 2002 10:23:18 +0000
Subject: Bug #15010 Updated: switch() problem: "+" matches "-"
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-77878@lists.php.net to get a copy of this message
ID: 15010
Updated by: hholzgra
Old Summary: switch() problem: "+" matches "-"
Reported By: matthew.somerville@trinity.oxford.ac.uk
Status: Closed
Bug Type: Variables related
Operating System: RISC OS
PHP Version: 4.1.0
Assigned To: alexwaugh
New Comment:

shall we add a configure test for it?


Previous Comments:
------------------------------------------------------------------------

[2002-01-23 05:05:04] alexwaugh@php.net

Caused by a bug in strtol(). A fix has been sent to the RISC OS C
library maintainer.

------------------------------------------------------------------------

[2002-01-12 19:28:30] matthew.somerville@trinity.oxford.ac.uk

Oh, I just assumed it was a problem with PHP, but if it
doesn't happen on anything else, obviously not. :) I'll
get in touch with the RISC OS porter.


------------------------------------------------------------------------

[2002-01-12 18:29:33] mfischer@php.net

Ok, sorry. I misread your report a bit ;)

So this applies only to RISC OS ? Can't reproduce this under linux.

------------------------------------------------------------------------

[2002-01-12 18:27:01] mfischer@php.net

Jesus man.

case statements not followed by a break; statement fall through.

Your code should read:

<? $k = "+";
   switch($k) {
     case "-": print "Oh no!"; break;
     case "+": print "Correct!"; break;
   }
?>

------------------------------------------------------------------------

[2002-01-12 18:21:28] matthew.somerville@trinity.oxford.ac.uk

<? $k = "+";
   switch($k) {
     case "-": print "Oh no!";
     case "+": print "Correct!";
   }
?>

outputs "Oh no!". I guess this is because as switch uses
==, + and - are both being automatically converted to the
number 0 which then matches? Could switch() perhaps use
=== instead of == in its comparison?


------------------------------------------------------------------------



Edit this bug report at http://bugs.php.net/?id=15010&edit=1



Thread (8 messages)

« previous php.dev (#77878) next »