chriskonnertz/deeply
Deeply is a PHP library for deep cloning objects and arrays. It recursively copies nested objects so duplicates share no references with the original, with a simple API and support for magic methods like __clone and __wakeup. Useful for snapshots, caching, and safe duplication without side effects.
Architecture fit. Deeply is a single-purpose, framework-agnostic utility rather than a Laravel-integrated package. That is actually a favorable architectural posture for a TPM scoping it: it has no service provider, no config surface, no middleware, and no opinion about the application layer. It fits cleanly as a leaf dependency inside domain services, action classes, or value-object factories. The relevant architectural question is not "does it fit Laravel" but "which object graphs in our codebase are safe to deep-copy." It is a good fit for DTOs, plain value objects, template/instance clone flows (e.g., cloning a project template into a new project), audit-diff snapshotting, and test fixtures. It is a poor fit for Eloquent model graphs with loaded relations, because a model's loaded relations carry query builders, connection objects, and event-related state that a naive deep clone can corrupt or fail on.
Integration feasibility. High. Composer install, a small public API for copying arbitrary PHP values, MIT license, no infrastructure. Nothing needs to be registered in the container and nothing needs to be bootstrapped. The realistic effort is not the install but the guardrails: defining which classes are copy-safe, wrapping the library behind a domain interface, and writing contract tests. A TPM should budget for the wrapper and tests, not the dependency.
Technical risk. Moderate but contained.
Closure, PDO/resource-backed handles). A recursive cloner must either skip them or it will throw. This is the highest-severity unknown and needs a spike before adoption in any graph containing Laravel services, collections with callbacks, or event dispatchers.replicate() for row duplication; Deeply should not be positioned as a replacement.Key questions.
SplObjectStorage keyed by original)?DateTimeImmutable, enums, readonly properties)?Stack fit. Compatible with a standard Laravel stack (PHP 8.1+, Composer 2). It lives in the domain/service layer, not the framework layer, so it does not constrain the Laravel version. The only coupling is PHP language semantics, which is the most stable surface available.
Migration path. There is nothing to migrate from if we use it for a new capability. If replacing ad-hoc approaches (manual clone, serialization round-trips via serialize/unserialize, or json_decode(json_encode())), the path is: introduce Deeply behind an ObjectCopier interface, port one call site, and run both implementations against a fixture suite before deleting the old path. A serialization round-trip is the closest existing behavior and the easiest benchmark for equivalence — with the caveat that serialization loses type fidelity and cannot handle closures at all, so Deeply should compare favorably.
Compatibility. Two axes to verify in a spike, not in production:
Sequencing.
Maintenance. Low ongoing effort for the dependency — there is nothing to configure. The real maintenance is ownership of the copy-safety contract: as new classes are added to the domain, someone must know whether they are safe to deep-copy. Assign that to the owning team and encode it as a marker interface or test, otherwise correctness erodes silently over months.
Support. Community-only, no SLA, no vendor. Given the single-maintainer profile and the 2023 last release, plan for the possibility of no upstream fixes. Mitigate by vendoring or maintaining a thin internal fork; the code surface is small enough that this is realistic for one engineer.
Scaling. Scaling is the sharpest operational concern. Deep copy is a full traversal with reflection: cost scales linearly with graph size but with a large constant, and memory roughly doubles at the moment of copy. It is appropriate for per-request, per-entity operations and inappropriate for bulk jobs over thousands of models, hot loops, or queue workers processing large batches. Set explicit guidance: copy DTOs and value objects, not hydrated model graphs; cap graph depth/size; prefer replicate() for Eloquent rows and plain clone for flat objects.
Failure modes. Ranked by expected impact:
Ramp-up. Very low for developers (the API is a single call), which is itself a risk: the low barrier invites misuse on graphs that are not copy-safe. Ramp-up effort should be spent on education, not API training — a short internal note on "what we deep-copy and what we never deep-copy," plus the wrapper, is sufficient. Expect roughly a half-day per engineer to become productive and a single owner-day to establish the safety contract.
How can I help you explore Laravel packages today?