https://github.com/symfony/polyfill-deepclone
Symfony polyfill for the deepclone extension
https://github.com/symfony/polyfill-deepclone
compatibility component deepclone javascript polyfill portable shim symfony symfony-component symfony-polyfill
Last synced: about 23 hours ago
JSON representation
Symfony polyfill for the deepclone extension
- Host: GitHub
- URL: https://github.com/symfony/polyfill-deepclone
- Owner: symfony
- License: mit
- Created: 2026-04-10T14:42:29.000Z (7 days ago)
- Default Branch: 1.x
- Last Pushed: 2026-04-14T12:09:40.000Z (3 days ago)
- Last Synced: 2026-04-14T15:27:36.096Z (3 days ago)
- Topics: compatibility, component, deepclone, javascript, polyfill, portable, shim, symfony, symfony-component, symfony-polyfill
- Language: PHP
- Homepage: https://symfony.com/polyfill-deepclone
- Size: 38.1 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Symfony Polyfill / DeepClone
============================
This package provides a pure-PHP implementation of the functions and exception
classes from the [deepclone extension](https://github.com/symfony/php-ext-deepclone):
- `deepclone_to_array(mixed $value, ?array $allowedClasses = null): array`
— converts any serializable PHP value graph into a pure array (only scalars
and nested arrays, no objects).
- `deepclone_from_array(array $data, ?array $allowedClasses = null): mixed`
— rebuilds the value graph from the array, preserving object identity,
references, cycles, and private property state.
- `DeepClone\NotInstantiableException` and `DeepClone\ClassNotFoundException`
When the native `deepclone` extension is loaded, this polyfill does nothing —
the extension provides the same functions 4–5× faster.
The array representation preserves PHP's copy-on-write for strings and scalar
arrays, making repeated cloning of a prototype significantly more memory
efficient than `unserialize(serialize())`. It also serves as a cache-friendly
serialization format: when dumped via `var_export()` into a `.php` file,
OPcache maps the array into shared memory, making deserialization essentially
free.
This is the same wire format used by Symfony's `VarExporter\DeepCloner`.
More information can be found in the
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).
License
=======
This library is released under the [MIT license](LICENSE).