Hi Tim Thank you and Derick for the work on this proposal.
On 18.06.26 15:47, Tim Düsterhus wrote:
All that said, you can find the RFC at: https://wiki.php.net/rfc/duration_class. It hopefully includes all the important explanation and also provides a rationale as to why we made the design decisions we made.
Some thoughts:
The Time\Duration class will also implement internal “comparison handlers”, which means that direct comparisons with operators such as < will work.
Can you explicitly spell out that this does not apply to arithmetic operators?
One thing worth specifying is how you're planning on handling the passing of Duration objects to APIs that do not support certain precisions. For example, PHPs sleep() is a thin wrapper around system sleep(), which only accepts seconds. This would internally need to be re-routed to usleep(), but even then usleep() only supports microseconds. What happens when we pass a duration of that scale to sleep()? Throw? Truncate? Round? (Let's disregard the existence of nanosleep() for the sake of the argument.)
The biggest concern for me is having to instantiate an object for all calls that take a duration, which seems like mostly unnecessary overhead. This is partially resolvable by adding support for storing immutable objects in shared memory, which works here because the class is readonly.
Ilija
