Re: int|float for DateTime::setTimestamp

From: Date: Wed, 14 Feb 2024 00:48:46 +0000
Subject: Re: int|float for DateTime::setTimestamp
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-122366@lists.php.net to get a copy of this message
> > just like the constructor accepts > new DateTime("@0.123456"); // 1970-01-01 00:00:00.123456 > new DateTime("@".microtime(true)); > > IMO setTimestamp should accept the same: > $dt->setTimestamp(0.123456); // 1970-01-01 00:00:00.123456 > $dt->setTimestamp(microtime(true)); > > Can we change setTimestamp to accept int|float? > made a PR https://github.com/php/php-src/pull/13383 You are probably already aware, but PHP 8.4 will have a new DateTime::get/setMicroseconds method[^1][^2] that accepts an integer microsecond value. That said, I personally think it makes sense to accept float values for fractions of seconds, but changing the parameter type WILL be be a BC break because all subclasses extending setTimestamp will not be compatible unless they are changed to int|float or wider. [^1]: https://github.com/php/php-src/commit/0016b3085cf06e8a189ecc53c31697e3a108dbdd [^2]: https://php.watch/versions/8.4/date-datetime-get-setMicroseconds

« previous php.internals (#122366) next »