php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47499 Buggy control flow when switching on 0 (zero)
Submitted: 2009-02-25 00:16 UTC Modified: 2009-02-25 01:00 UTC
From: mpb dot mail at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.8 OS: Linux
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: mpb dot mail at gmail dot com
New email:
PHP Version: OS:

 

 [2009-02-25 00:16 UTC] mpb dot mail at gmail dot com
Description:
------------
When switching on 0 (zero), control flow executes the wrong case.

Reproduce code:
---------------
<?php

$x = 0;
switch ($x) {
  case 'foo':
    print "foo == $x ?\n";
    break;
  case 0:
    print "0 == $x ?\n";
    break;
  default:
    print "default: \$x == $x  ?\n";
    break; }

?>


Expected result:
----------------
0 == 0 ?


Actual result:
--------------
foo == 0 ?


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-25 00:56 UTC] crrodriguez at opensuse dot org
$x is an integer, and 'foo' is a string in the first case..which  gets casted to an integer so it can be compared... it is the expected behavior...
 [2009-02-25 01:00 UTC] mpb dot mail at gmail dot com
Ah.  You are right.  PHP is a crazy language.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Sep 14 19:00:01 2025 UTC