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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nikhiltiwari005 at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC