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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
40 + 28 = ?
Subscribe to this entry?

 
 [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: Thu Jul 07 01:04:05 2022 UTC