spatie/php-cloneable
Trait for PHP 8.1+ that makes objects with readonly properties cloneable. Safely “clone with changes” by copying an object while overriding readonly fields—handy until PHP gets native clone-with support.
readonly properties (PHP 8.1+), critical for scenarios like:
__clone() overrides).readonly properties. Low maintenance cost (MIT-licensed, actively updated by Spatie).readonly properties (e.g., Eloquent models, DTOs, or value objects).readonly cloning quirks (see Stitcher.io’s deep dive).__clone() implementations or serialization/deserialization hacks.readonly objects).serialize()/unserialize() or libraries like jms/serializer).For Executives:
"This package lets us clone objects with readonly properties in PHP 8.1—critical for features like drafts, undo/redo, or data isolation—without custom engineering. It’s a low-risk, high-reward upgrade: Spatie maintains it, it’s MIT-licensed, and it saves dev time on cloning edge cases. For example, it could enable a ‘clone cart’ feature in our e-commerce platform with minimal effort."
For Engineering:
"The Cloneable trait from Spatie solves PHP 8.1’s readonly property cloning issue elegantly. Instead of writing fragile __clone() methods or serializing objects, we add one trait to our models/DTOs. It’s battle-tested (used in Spatie’s other packages), has zero dependents (so no hidden risks), and aligns with our PHP 8.1 migration. Let’s use it for [specific use case, e.g., ‘user profile snapshots’] to avoid reinventing the wheel."
For Developers:
"Need to clone a model with readonly fields? Just use use Cloneable. No more errors like ‘Cannot assign to property X in clone’. Works out of the box with Laravel Eloquent or plain PHP objects. Docs are clear, and Spatie’s support is reliable."
How can I help you explore Laravel packages today?