php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81168 microtime return variable's value is changing inside loop
Submitted: 2021-06-18 09:34 UTC Modified: 2021-06-18 09:40 UTC
From: nikhiltiwari005 at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 8.0.7 OS: Linux
Private report: No CVE-ID: None
 [2021-06-18 09:34 UTC] nikhiltiwari005 at gmail dot com
Description:
------------
<?php
$arr = [];
for ($i = 0; $i < 5000000; $i++) {
    $mct = microtime(true);
    $arr[$mct] = $mct;
}
print_r($arr);

Expected result:
----------------
<?php
$arr = [];
for ($i = 0; $i < 5000000; $i++) {
    $mct = microtime(true);
    $arr[$mct] = $mct;
}
print_r($arr);
// result 
Array
(
    [1624008537] => 1624008538
    [1624008538] => 1624008538.6062
)
Key is diffrent and value is diffrent of same variable.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-06-18 09:40 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2021-06-18 09:40 UTC] nikic@php.net
You can look forward to the PHP 8.1 release, where this script will spam you with messages of the type

> Deprecated: Implicit conversion from float 1624009164.693986 to int loses precision

telling you exactly what went wrong.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun May 22 21:05:44 2022 UTC