PHP 8.1: cloning and changing readonly properties
Read OriginalThe 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.
Comments
No comments yet
Be the first to share your thoughts!
Browser Extension
Get instant access to AllDevBlogs from your browser