Re: [RFC] Duration class

From: Date: Tue, 23 Jun 2026 08:01:22 +0000
Subject: Re: [RFC] Duration class
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-131497@lists.php.net to get a copy of this message
Hi Am 2026-06-23 02:36, schrieb Peter Stalman:
1. Are there other classes planned for the \Time namespace? I think we
Yes, see also the “Future Scope” section.
should avoid using root namespaces and instead decide on a common namespace, so something like \Std\Time or \Php\Time. Although I realized that topic is a bit above this particular RFC, but worth considering for internals as more root namespaces are added.
The use of the namespace is in line with the namespace policy that you can find at https://github.com/php/policies/blob/main/coding-standards-and-naming.rst#namespaces. It was (almost) unanimously accepted in 2021: https://wiki.php.net/rfc/namespaces_in_bundled_extensions. This policy has been the basis of Random\* (8.2), Dom\* (8.4), Uri\* (8.5).
2. Since the class is marked final (why?), I would recommend we also create a DurationInterface and use _that_ as the type wherever it is used. This would alleviate some of the concerns people have with making it final. For example, see popular packages like \Carbon\Carbon extends \DateTime and implements \DateTimeInterface.
It's a value object, there is only one reasonable implementation that preserves all the invariants that users expect. This topic has previously also been discussed as part of the URI extension (somewhere here: https://news-web.php.net/php.internals/123997). Best regards Tim Düsterhus

« previous php.internals (#131497) next »