Brent 7/6/2021

PHP 8.1: cloning and changing readonly properties

Read Original

The article details a specific limitation in PHP 8.1 where readonly properties cannot be modified after initialization, preventing them from being changed during object cloning. It presents a workaround using a custom package (spatie/php-cloneable) that provides a `Cloneable` trait, adding a `with()` method to objects for cloning with overridden property values, while noting its caveats like skipping the constructor.

PHP 8.1: cloning and changing readonly properties

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week

1
The Beautiful Web
Jens Oliver Meiert 2 votes
2
Container queries are rad AF!
Chris Ferdinandi 2 votes
4
LLM Use in the Python Source Code
Miguel Grinberg 1 votes
5
Wagon’s algorithm in Python
John D. Cook 1 votes