From:             codingcarlos at gmail dot com
Operating system: windows/linux
PHP version:      Irrelevant
Package:          Testing related
Bug Type:         Bug
Bug description:Bug on switch in case 0

Description:
------------
When a variable is stored via $_GET method (even when parsing to
integer) and used in a switch, fails on case 0.

When you use it like: example.php?num=0 
You will get the result: "The number 0 is higer than 5." (Obiously
fail)

But if you use 00 instead of 0: example.php?num=00 
You will get the result: "The number 00 is lower than 2." (Which is
true)

It also works with " 0": example.php?num= 0
You will get the result: "The number 00 is lower than 2." (Which is
true)

Test script:
---------------
$number = $_GET['num'];
// $number = intval($_GET['num']);
// $number = (int) $_GET['num'];

    switch ($number) {
        case ($number<2): 
            $result = 'lower than 2'; 
            break;
        case ($number<5): 
            $result = 'lower than 5'; 
            break;
        case ($number>=5): 
            $result = 'higer than 5'; 
            break; // Se mete aqui con nota = 10
    }
    echo "The number " . $number . " is " . $result . ".";

Expected result:
----------------
The number 0 is lower than 2.

Actual result:
--------------
The number 0 is higer than 5.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=68346&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=68346&r=trysnapshot54
Try a snapshot (PHP 5.5):   
https://bugs.php.net/fix.php?id=68346&r=trysnapshot55
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=68346&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=68346&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=68346&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=68346&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=68346&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=68346&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=68346&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=68346&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=68346&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=68346&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=68346&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68346&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=68346&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=68346&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=68346&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68346&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=68346&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=68346&r=mysqlcfg


-- 
PHP Quality Assurance Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to