Designed Once, Usable Everywhere: why PHP 8.6 adds SortDirection and Time\Duration to the standard library
u/timwolla wrote up the reasoning behind two small PHP 8.6 additions: a SortDirection enum and a Time\Duration class.
The short version: a GitHub search found 150+ mutually incompatible SortDirection enums, and PHP's own stdlib expresses durations in at least six different units and formats. Putting one canonical type in core gives libraries a common language and removes the glue code between them.
The post also covers:
- Why the RFCs were intentionally kept minimal, with a clearly stated future scope
- Using new namespaces (
Random\,Dom\,Uri\,Time\) to replace legacy APIs without breaking BC - The in-discussion
Time\Instant/Time\ClockRFC that builds onDuration - How to help: testing pre-releases, accepting the new types via union types in your libraries, and weighing in on internals
[link] [comments]