- How do I install Deeply in a Laravel application?
- Install it with composer require chriskonnertz/deeply. Because Deeply is a framework-agnostic utility library, there is no service provider to register and nothing to publish. Inside a Laravel app you can call it directly from an action class, domain service, or test, or wrap it behind your own ObjectCopier interface. Composer 2 and PHP 8.1 or newer are the practical requirements.
- Does Deeply need a service provider or config file in Laravel?
- No. Deeply ships no service provider, no configuration surface, and no auto-discovery entry, so installing it adds a leaf dependency and nothing else. It never touches the container, middleware, or the framework layer. That keeps it stable across Laravel upgrades, but it also means you provide your own wrapper or facade if you want one.
- What is the difference between Deeply and PHP's native clone keyword?
- PHP's clone keyword performs a shallow copy, so nested objects are still shared between the original and the duplicate. Deeply walks the whole object graph recursively so the copy shares no references with the source. That matters for snapshots, template cloning, and test fixtures where mutating the copy must not affect the original.
- Can I use Deeply to duplicate Eloquent models?
- You should not. Loaded Eloquent models carry query builders, connection state, and event-related state, and deep-copying them can produce objects that look like models but behave incorrectly. Laravel already provides replicate() for duplicating a row and its attributes. Use Deeply for plain value objects, DTOs, and configuration-style graphs instead.
- Does Deeply handle objects that cannot be cloned, such as Closure or PDO?
- This is the highest-risk unknown and deserves a spike before you adopt Deeply in graphs containing closures, PDO handles, streams, or other resource-backed objects. Some PHP objects simply cannot be cloned, so a recursive cloner must either skip them or throw. Test against your real object graphs first, especially anything holding a Laravel service, an event dispatcher, or a collection with callbacks.
- Which PHP and Laravel versions does Deeply support?
- Plan on PHP 8.1 or newer with Composer 2. Because Deeply lives in the domain layer rather than the framework layer, it does not constrain your Laravel version at all. Check the declared PHP constraint and CI matrix in the package's composer.json before pinning it, since the last release landed in July 2023.
- Is Deeply still maintained, and what happens if it is abandoned?
- Deeply is a single-maintainer package with a last release around July 2023 and roughly 229 stars, so low activity is a real but contained risk. The MIT license and small code surface make fork-and-vendor a practical mitigation. Treat it as plumbing rather than a platform bet and keep it behind your own interface so swapping it out stays a one-file change.
- How does Deeply compare to serialize/unserialize or json_encode for copying objects?
- A serialize/unserialize round trip is the closest existing behaviour and a reasonable equivalence benchmark. It loses type fidelity for some values and cannot handle closures at all, while json_encode and json_decode flatten objects into arrays and drop object identity entirely. Deeply copies the live object graph instead, which is exactly why it needs careful tests around uncloneable and immutable objects.
- How do I safely introduce Deeply into an existing Laravel codebase?
- Put Deeply behind a small ObjectCopier interface in your domain layer, port a single call site, and run both implementations against a fixture suite before deleting the old path. Define which classes are copy-safe and add contract tests for each of them. The real effort is the guardrails and tests, not the composer require.
- What is the performance and memory cost of deep cloning large object graphs?
- Cloning is O(n) over the full object graph and relies on reflection, so time and memory scale with graph size. Wide relation graphs or large collections can cause memory spikes even when the copy is logically correct. Benchmark against your largest realistic graph before putting it on a hot path, and prefer cloning small, purpose-built value objects.