php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19012 is_integer doesn't return true
Submitted: 2002-08-21 03:45 UTC Modified: 2002-08-21 05:26 UTC
From: craesh at craesh dot net Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.2.2 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: craesh at craesh dot net
New email:
PHP Version: OS:

 

 [2002-08-21 03:45 UTC] craesh at craesh dot net
It's just that is_integer( $a_double_value ) doesn't seem to return true nor anything else if the double matches a integer value. Just try this script:

<?php

$a = 2.0;
$b = 1.0;
echo is_integer( $a/$b );
echo is_integer( 2.0 ); // Doesn't output anything

echo is_integer( 2 );
echo is_integer( 2/1 );
echo is_int( 2 );  // These 3 test do output "1"

?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-21 04:11 UTC] cynic@php.net
2.0 is not an integer. is_integer(2.0) returns false, which is '' in string contexts.

 [2002-08-21 04:37 UTC] craesh at craesh dot net
Hi!

I still think is_integer() is buggy, I've this code-extract wich worked fine with PHP 4.1.2 and doesn't work with 4.2.2

$MaxWidth = "50"; 
// ...
$PerLines = floor(400/$MaxWidth);
//...
while( ... ) {
  // ...
  if (is_integer($i/$PerLines) ) { 
    //... 
  } 
}

It's actualy an extract from the phpmychat (don't know wich version, I think one of the latest), on PHP 4.1.2 the if-clause matches every 8 iterations, on PHP 4.2.2 never. If you exchance the if-clause with this:

if ( $i % 8 == 0 ) {

you get a match every 8 iterations, so is_integer has to be buggy.

Thanks!
Sacher
 [2002-08-21 05:22 UTC] msopacua at idg dot nl
It's still phpmychat's error - or a fixed bug in 4.1.2.
Return type of floor is float - not integer:
gettype(floor(400/"50"));

Consistent with:
http://www.php.net/float
 [2002-08-21 05:26 UTC] cynic@php.net
i don't see what makes you so sure about is_integer() bugginess. nothing in what you posted supports your claim.

if ($i % 8 == 0) is *not* equivalent to the is_integer() test, because it actually *ignores* the type of the result of the modulo expression.

besides, i can't reproduce it either:

    script:

    echo PHP_VERSION, "\n";
    var_dump(is_integer(8/(400/50)));

    output:

    4.2.2
    bool(true)


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 22:01:27 2024 UTC