This article is about a topic that didn't make the cut for my latest book, https://leanpub.com/recipes-for-decoupling. I don't know where I first heard it, but PHP's DateTimeImmutable is not immutable: getTimestamp().
But an even bigger surprise might be that if a constructor is public, it's just another method that you can call.
This is exactly the point I want to make in this article: DateTimeImmutable is already effectively immutable because nobody mutates its state.
The downside is that we have to do more work on the classes to make their instances truly immutable.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.