Source: stitcher.io

PHP 8.1: readonly properties

Category: PHP, PHP

We think you might be interested in this job:

Scout APM helps PHP developers pinpoint N+1 queries, memory leaks & more so you can troubleshoot fast & get back to coding faster. Take for example a look at a DTO in PHP 5.6: And compare it to its PHP 8.0's equivalent: That's already quite the difference, though I think there's still one big issue: all those getters.

So, if you can't change readonly properties, and if you can't unset them, how can you create a copy of your DTOs or VOs and change some of its data?

Well, you can copy over objects with changed readonly properties, if you rely on a little bit of reflection magic.

The readonly properties RFCWhat's new in PHP 8.1Evolution of objects in PHP over the yearsCloning readonly properties
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Community Partners