1.2.905. PHP 7.1 Microseconds

PHP supports microseconds in DateTime class and date_create() function. This was introduced in PHP 7.1.

In previous PHP versions, those dates only used seconds, leading to lazy comparisons : This code displays true in PHP 7.0 and older, (unless the code was run too close from the next second). In PHP 7.1, this is always false.

This is also true with DateTime : This evolution impacts mostly exact comparisons (== and ===). Non-equality (!= and !==) will probably be always true, and should be reviewed.

<?php

$now = date_create();
usleep(10);              // wait for 0.001 ms
var_dump($now == date_create());

?>

See also Backward incompatible changes.

1.2.905.1. Suggestions

  • Check direct comparisons of date

1.2.905.2. Specs

Short name

Php/Php71microseconds

Rulesets

All, Changed Behavior, CompatibilityPHP71

Exakat since

0.8.9

PHP Version

All

Severity

Major

Time To Fix

Quick (30 mins)

Changed Behavior

PHP 7.1 - More

Precision

Very high

Features

microtime

Available in

Entreprise Edition, Exakat Cloud