PHP 7 vs 8 DateTime behavior with float timestamps

Viewed 68

This example: https://onlinephp.io/c/3af93

<?php

new DateTime("@0.1");

throws an error in PHP 7 but in PHP 8 it will successfully parse the timestamp.

I am trying to understand why this behaves differently from the previous PHP version. After looking through the PHP 7 vs 8 changelog, I could not find any direct reference to this behavior.

Is this an undocumented change or is this related to anything different?

1 Answers

From my point of view, Documentation is same for PHP 7.* and PHP 8.*, Difference seems to be in echoing out Fatal error (Or Notices Or Warnings). They also need to echo out for PHP 8 as well.

If you refer to the documentation for DateTime::__construct(),

Note: The $timezone parameter and the current timezone are ignored when the $datetime parameter either is a UNIX timestamp (e.g. @946684800) or specifies a timezone (e.g. 2010-01-28T15:00:00+02:00).

`

Related