php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43769 Comparison wrong
Submitted: 2008-01-06 15:16 UTC Modified: 2008-01-06 19:16 UTC
From: hardisc15 at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.5 OS: Windows XP
Private report: No CVE-ID: None
 [2008-01-06 15:16 UTC] hardisc15 at gmail dot com
Description:
------------
Floating point should have equal treatment of whole number in this example?
Sorry, I am using translator.

Reproduce code:
---------------
$teste=4.1;//$teste='4.1';
$confere=array(4=>'');
if(isset($confere[$teste])){echo 'BUG';}else{echo 'NO BUG';}

Expected result:
----------------
NO BUG

Actual result:
--------------
BUG

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-06 19:16 UTC] felipe@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Says the documentation:
"A key may be either an integer or a string."

Therefore, the float value is converted to integer.

<?php

var_dump(array(1.4 => 'foobar'));

/*
array(1) {
  [1]=>
  string(6) "foobar"
}
*/
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Dec 14 19:00:01 2025 UTC