php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53204 IF Statement Long String
Submitted: 2010-10-29 22:50 UTC Modified: 2010-11-02 03:51 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: diemuzi at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.3.3 OS: Archlinux
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: diemuzi at gmail dot com
New email:
PHP Version: OS:

 

 [2010-10-29 22:50 UTC] diemuzi at gmail dot com
Description:
------------
I was testing long strings of numbers against an IF statement (see test) script and it was outputting information which was not true.

Test script:
---------------
This works:

$o = 33;
if ($o >= 29 && $o <= 32)
{
    echo "true";
} else {
    echo "false";
}

This does not work:

$o = 336571324099282374385465584513479344133;
if ($o >= 336571324099282374385465584513479344129 && $o <= 336571324099282374385465584513479344132)
{
    echo "true";
} else {
    echo "false";
}

Expected result:
----------------
In the working example, the output should be false. This is working as expected.

In the non-working example, the output should be false. However, it is returning true.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-30 23:04 UTC] phristen at yahoo dot com
PHP integers are 32 bit.
The actual value of $o is not what you think it is... Do this:
var_dump($o);
 [2010-11-02 03:51 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2010-11-02 03:51 UTC] aharvey@php.net
As comment #1 indicates, this is due to the fact that you're actually dealing with floating point values, not integers.

Not a bug -> closing.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 02:01:34 2025 UTC