PHPackages                             symfony/deepclone - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. symfony/deepclone

ActivePhp-ext[Utility &amp; Helpers](/categories/utility)

symfony/deepclone
=================

Export any serializable PHP values as pure arrays - accelerator for Symfony's DeepCloner

v0.6.1(2w ago)153.3k↑95.5%3[2 PRs](https://github.com/symfony/php-ext-deepclone/pulls)MITCPHP &gt;=8.2CI passing

Since Apr 10Pushed 2w ago2 watchersCompare

[ Source](https://github.com/symfony/php-ext-deepclone)[ Packagist](https://packagist.org/packages/symfony/deepclone)[ Docs](https://github.com/symfony/php-ext-deepclone)[ Fund](https://symfony.com/sponsor)[ GitHub Sponsors](https://github.com/fabpot)[ RSS](/packages/symfony-deepclone/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (10)DependenciesVersions (13)Used By (0)

deepclone
=========

[](#deepclone)

[![CI](https://github.com/symfony/php-ext-deepclone/actions/workflows/test.yml/badge.svg)](https://github.com/symfony/php-ext-deepclone/actions/workflows/test.yml)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

A PHP extension that deep-clones any serializable PHP value while preserving copy-on-write for strings and arrays — resulting in lower memory usage and better performance than `unserialize(serialize())`.

It works by converting the value graph to a pure-array representation (only scalars and nested arrays, no objects) and back. This array form is the wire format used by Symfony's [`VarExporter\DeepCloner`](https://symfony.com/doc/current/components/var_exporter.html), making the extension a transparent drop-in accelerator.

Use cases
---------

[](#use-cases)

**Repeated cloning of a prototype.** Calling `unserialize(serialize())` in a loop allocates fresh copies of every string and array, blowing up memory. This extension preserves PHP's copy-on-write: strings and scalar arrays are shared between clones until they are actually modified.

```
$payload = deepclone_to_array($prototype);
for ($i = 0; $i < 1000; $i++) {
    $clone = deepclone_from_array($payload);  // fast, COW-friendly
}
```

**OPcache-friendly cache format.** The pure-array payload is suitable for `var_export()`. When cached in a `.php` file, OPcache maps it into shared memory — making the "unserialize" step essentially free:

```
// Write:
file_put_contents('cache.php', '
