Cloning readonly properties
Written on 2023-03-20Join 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?
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:
- To Route or To Action - That is the Question — Tomas recently discovered the Laravel ecosystem, and is writing a lot of great content about it.
- Valet 4.0 is released — The new major release of Valet is here! There are a couple of new features, but mainly it's internal changes to make debugging easier and make Valet more stable.
- Discovering PHP's first-class callable syntax — Freek takes a close look at first-class callables.
- The future of Pest v2 — Nuno talks about Pest v2, which is actually getting released today! Freek also wrote about it here.
- Slashdash — A silly little idea I read about: scope-aware code comments.
- PHP Core Roundup #10 — What's been happening in PHP Core Land.
- Punchcard - Object Configs for Laravel — Based on a blog post of mine, Tomas went ahead and built a package for object-based config files in Laravel. Worth giving a try, in my opinion.
- Tech-last — Robin writes about "new things". His thoughts resonate.
- Finally, I'd like to mention my GitHub Sponsors page one more time, and thank everyone who's pitching in, you can read about the story here.
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