1.2.1478. date() versus DateTime Preference¶
Processing dates is done with date() functions or DateTime <https://www.php.net/`datetime>`_ classes.
In the date() team, there are the following functions : date(), time(), getdate(), localtime(), strtotime(), strptime(), gmdate(), strftime(), mktime(), gmktime().
In the DateTime <https://www.php.net/`datetime>`_ team, there are the instantiation of DateTime <https://www.php.net/`datetime>`_ and DateTimeImmutable <https://www.php.net/`datetimeimmutable>`_; the DateTime::createFromInterface(), DateTime::createFromFormat(), DateTime::createFromImmutable() and DateTime::createFromMutable().
The analyzed code has less than 10% of one of them : for consistency reasons, it is recommended to make them all the same.
<?php
// be consistent
$date = date();
$time = time();
$date = date();
$time = time();
$date = date();
$time = time();
$date = date();
$time = time();
$date = date();
$time = time();
$date = date();
$time = time();
// Be consistent, always use the same.
$date = new DateTime();
?>
1.2.1478.1. Connex PHP features¶
1.2.1478.1.1. Specs¶
Short name |
Structures/DateTimePreference |
Rulesets |
|
Exakat since |
2.4.9 |
PHP Version |
All |
Severity |
|
Time To Fix |
|
Precision |
Very high |
Available in |