Hi

On 2026-09-30 21:48, Tim Düsterhus wrote:
=========
Comment 5
=========
The RFC introduces a SystemClock class:

```php
<?php

final readonly class SystemClock implements \Time\Clock
{
    public function __construct() {}

    /**
     * The current instant, at the resolution offered by the platform
     * clock,
     * which is generally coarser than nanoseconds.
     *
     * Returned values are not guaranteed to be monotonically
     * increasing across calls.
     */
    public function now(): \Time\Instant {}
}

?>
```

Why is SystemClock not a Singleton? Can there be multiple different
system clocks in practice? I believe a System Clock, with the emphasis
on "System" is a System Wide clock. This clock is not bound to PHP,
but to all processes running on the system, including Apache,
shell-scripts, NGINX and others.

Conceptually there is only one `SystemClock` and internally each `SystemClock` object accesses the same clock source provided by the operating system. But you are making a good point here: Replacing the constructor with a static `::get()` method or similar would make that explicit and would also allow for reducing memory usage when `SystemClock` objects are obtained at different places in the code (instead of being pulled from a dependency injection container). I'll put this on my list to discuss with Derick (and am happy to receive naming suggestions for such a static getter).

We have now made the `SystemClock` a singleton with a `SystemClock::get()` factory / getter. The constructor is private now.

Best regards
Tim Düsterhus

Reply via email to