|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
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?


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-12 18:27 UTC]
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]
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]
Caused by a bug in strtol(). A fix has been sent to the RISC OS C library maintainer.
 [2002-01-23 05:23 UTC]
shall we add a configure test for it?
 [2002-01-24 10:05 UTC]
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-2021 The PHP Group
All rights reserved.
Last updated: Wed Oct 20 11:03:34 2021 UTC