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
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: 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 18:01:29 2024 UTC