Cloning readonly properties

Written on 2023-03-20

Join over 14k subscribers on my mailing list. I write about PHP news, share programming content from across the web, keep you up to date about what's happening on this blog, my work on Tempest, and more.

You can subscribe by sending an email to brendt@stitcher.io.

It's been exactly one month since I sent my last newsletter. There's of course a very good reason for this longer period of silence: our baby girl, Alina Lore Roose, was born! Despite it being a difficult pregnancy with several complications, Alina is doing great, and we're so happy and blessed to have her in our lives.

I will keep taking things slow for the coming month though, as I'm only working a couple of days a week. But I am happy being able to send out this newsletter, because I've got quite a lot to share with you after a full month. Let's begin!

Opinion-driven design

I did manage to make one video over the past month. This one is about how I favor "opinion-driven design". I'm very curious what you think about the topic, but also how you like this story telling format. Will you reply with your thoughts?

Video Thumbnail

Click to watch

Cloning readonly properties

There's a newly accepted RFC that will allow overwriting readonly properties while cloning an object. Beware though: you can only overwrite readonly properties within an object's __clone method:

readonly class Post
{
    public function __construct(
        public string $title,
        public string $author,
        public DateTime $createdAt,
    ) {}
    
    public function __clone()
    {
        $this->createdAt = new DateTime(); 
        // This is allowed,
        // even though `createdAt`
        // is a readonly property.
    }
}

It's definitely a useful feature for making deep clones of readonly classes, but I also have some side notes to make. I wrote them down in a dedicated blog post.

Roundup

There were quite a lot of great posts written during my month off. Here are a couple that stood out:


That's it for today's newsletter, I'm happy to be back, but I'm also happy being able to take a slow for a couple more weeks!

Until next time

Brent

Join over 14k subscribers on my mailing list. I write about PHP news, share programming content from across the web, keep you up to date about what's happening on this blog, my work on Tempest, and more.

You can subscribe by sending an email to brendt@stitcher.io.

Noticed a tpyo? You can submit a PR to fix it.
HomeRSSNewsletterDiscord© 2025 stitcher.io