Menu

Designed Once, Usable Everywhere: why PHP 8.6 adds SortDirection and Time\Duration to the standard library

#php#redditr#time#sortdirection#duration
Reading 0:00
15s threshold

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\Clock RFC that builds on Duration
  • How to help: testing pre-releases, accepting the new types via union types in your libraries, and weighing in on internals
submitted by /u/elizabethn
[link] [comments]