php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15010 switch() problem: "+" matches "-"
Submitted: 2002-01-12 18:21 UTC Modified: 2002-01-24 10:05 UTC
From: matthew dot somerville at trinity dot oxford dot ac dot uk Assigned: alexwaugh (profile)
Status: Closed Package: Variables related
PHP Version: 4.1.0 OS: RISC OS
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: matthew dot somerville at trinity dot oxford dot ac dot uk
New email:
PHP Version: OS:

 

 [2002-01-12 18:21 UTC] matthew dot somerville at trinity dot oxford dot ac dot 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?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-12 18:27 UTC] 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:29 UTC] 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 19:28 UTC] matthew dot somerville at trinity dot oxford dot ac dot 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-23 05:05 UTC] alexwaugh@php.net
Caused by a bug in strtol(). A fix has been sent to the RISC OS C library maintainer.
 [2002-01-23 05:23 UTC] hholzgra@php.net
shall we add a configure test for it?
 [2002-01-24 10:05 UTC] alexwaugh@php.net
I could add a configure test for it, but PHP is linked statically to the C library, and it is not (yet) trivial to compile PHP for RISC OS, so at the moment virtually everyone uses the precompiled binaries I put on my website.
There were also some fairly major bugs in the C library that were fixed recently, and so using an uptodate version is important.
I think perhaps that the configure check could abort the configure script with an error if it detects an old version, and force the user to upgrade their C library, rather than providing a replacement function.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Sep 25 16:01:24 2020 UTC