PHPackages                             symfony/var-exporter - 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/var-exporter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

symfony/var-exporter
====================

Provides tools to export, instantiate, hydrate, clone and lazy-load PHP objects

v8.0.0(6mo ago)2.1k378.1M—6.8%620MITPHPPHP &gt;=8.4

Since Oct 29Pushed 1w ago4 watchersCompare

[ Source](https://github.com/symfony/var-exporter)[ Packagist](https://packagist.org/packages/symfony/var-exporter)[ Docs](https://symfony.com)[ Fund](https://symfony.com/sponsor)[ GitHub Sponsors](https://github.com/fabpot)[ RSS](/packages/symfony-var-exporter/feed)WikiDiscussions 8.1 Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (265)Used By (20)Security (1)

VarExporter Component
=====================

[](#varexporter-component)

The VarExporter component provides various tools to deal with the internal state of objects:

- `VarExporter::export()` allows exporting any serializable PHP data structure to plain PHP code. While doing so, it preserves all the semantics associated with the serialization mechanism of PHP (`__wakeup`, `__sleep`, `Serializable`, `__serialize`, `__unserialize`);
- `DeepCloner` deep-clones PHP values while preserving copy-on-write benefits for strings and arrays, making it faster and more memory efficient than `unserialize(serialize())`;
- `Lazy*Trait` can make a class behave as a lazy-loading ghost or virtual proxy.

The component depends on the native [`ext-deepclone`](https://github.com/symfony/php-ext-deepclone)extension for maximum performance, or on [its polyfill](https://github.com/symfony/polyfill/tree/main/src/DeepClone)as a fallback. In addition to functions `deepclone_to_array()` and `deepclone_from_array()`which are leveraged by `DeepCloner` and `VarExporter::export()`, the extension provides a `deepclone_hydrate()` function that lets you instantiate / hydrate objects without calling their constructor, including private, protected and readonly properties.

VarExporter::export()
---------------------

[](#varexporterexport)

The reason to use `VarExporter::export()` *vs* `serialize()` or [igbinary](https://github.com/igbinary/igbinary) is performance: thanks to OPcache, the resulting code is significantly faster and more memory efficient than using `unserialize()` or `igbinary_unserialize()`.

Unlike `var_export()`, this works on any serializable PHP value.

It also provides a few improvements over `var_export()`/`serialize()`:

- the output is PSR-2 compatible;
- the output can be re-indented without messing up with `\r` or `\n` in the data;
- missing classes throw a `ClassNotFoundException` instead of being unserialized to `PHP_Incomplete_Class` objects;
- references involving `SplObjectStorage`, `ArrayObject` or `ArrayIterator`instances are preserved;
- `Reflection*`, `IteratorIterator` and `RecursiveIteratorIterator` classes throw an exception when being serialized (their unserialized version is broken anyway, see ).

DeepCloner
----------

[](#deepcloner)

`DeepCloner::deepClone()` deep-clones a PHP value. Unlike `unserialize(serialize())`, it preserves PHP's copy-on-write semantics for strings and arrays, resulting in lower memory usage and better performance:

```
$clone = DeepCloner::deepClone($originalObject);
```

For repeated cloning of the same structure, create an instance to amortize the cost of graph analysis:

```
$cloner = new DeepCloner($prototype);
$clone1 = $cloner->clone();
$clone2 = $cloner->clone();
```

Lazy Proxies
------------

[](#lazy-proxies)

Since version 8.4, PHP provides support for lazy objects via the reflection API. This native API works with concrete classes. It doesn't with abstracts nor with internal ones.

This components provides helpers to generate lazy objects using the decorator pattern, which works with abstract or internal classes and with interfaces:

```
$proxyCode = ProxyHelper::generateLazyProxy(new ReflectionClass(AbstractFoo::class));
// $proxyCode should be dumped into a file in production envs
eval('class FooLazyProxy'.$proxyCode);

$foo = FooLazyProxy::createLazyProxy(initializer: function (): AbstractFoo {
    // [...] Use whatever heavy logic you need here
    // to compute the $dependencies of the $instance
    $instance = new Foo(...$dependencies);
    // [...] Call setters, etc. if needed

    return $instance;
});
// $foo is now a lazy-loading decorator object. The initializer will
// be called only when and if a *method* is called.
```

Resources
---------

[](#resources)

- [Documentation](https://symfony.com/doc/current/components/var_exporter.html)
- [Contributing](https://symfony.com/doc/current/contributing/index.html)
- [Report issues](https://github.com/symfony/symfony/issues) and [send Pull Requests](https://github.com/symfony/symfony/pulls)in the [main Symfony repository](https://github.com/symfony/symfony)

###  Health Score

81

—

ExcellentBetter than 100% of packages

Maintenance84

Actively maintained with recent releases

Popularity78

Solid adoption and visibility

Community47

Growing community involvement

Maturity98

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 63% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~10 days

Recently: every ~34 days

Total

265

Last Release

56d ago

Major Versions

v6.4.25 → v7.3.32025-08-18

v6.4.26 → 7.3.x-dev2025-09-11

v7.4.0-BETA1 → v8.0.0-BETA12025-09-11

6.4.x-dev → 7.4.x-dev2026-03-10

7.4.x-dev → 8.0.x-dev2026-03-10

PHP version history (9 changes)v4.2.0-BETA1PHP ^7.1.3

v5.0.0-BETA1PHP ^7.2.9

v5.0.0PHP ^7.2.5

v5.0.9PHP &gt;=7.2.5

v4.4.13PHP &gt;=7.1.3

v6.0.0-BETA1PHP &gt;=8.0.2

v6.1.0-BETA1PHP &gt;=8.1

v7.0.0-BETA1PHP &gt;=8.2

v8.0.0-BETA1PHP &gt;=8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/47313?v=4)[Fabien Potencier](/maintainers/fabpot)[@fabpot](https://github.com/fabpot)

---

Top Contributors

[![nicolas-grekas](https://avatars.githubusercontent.com/u/243674?v=4)](https://github.com/nicolas-grekas "nicolas-grekas (302 commits)")[![fabpot](https://avatars.githubusercontent.com/u/47313?v=4)](https://github.com/fabpot "fabpot (62 commits)")[![derrabus](https://avatars.githubusercontent.com/u/1506493?v=4)](https://github.com/derrabus "derrabus (40 commits)")[![xabbuh](https://avatars.githubusercontent.com/u/1957048?v=4)](https://github.com/xabbuh "xabbuh (22 commits)")[![alexandre-daubois](https://avatars.githubusercontent.com/u/2144837?v=4)](https://github.com/alexandre-daubois "alexandre-daubois (8 commits)")[![keradus](https://avatars.githubusercontent.com/u/2716794?v=4)](https://github.com/keradus "keradus (5 commits)")[![fancyweb](https://avatars.githubusercontent.com/u/3658119?v=4)](https://github.com/fancyweb "fancyweb (4 commits)")[![Tobion](https://avatars.githubusercontent.com/u/610090?v=4)](https://github.com/Tobion "Tobion (4 commits)")[![jderusse](https://avatars.githubusercontent.com/u/578547?v=4)](https://github.com/jderusse "jderusse (3 commits)")[![alamirault](https://avatars.githubusercontent.com/u/9253091?v=4)](https://github.com/alamirault "alamirault (2 commits)")[![Amoifr](https://avatars.githubusercontent.com/u/31698966?v=4)](https://github.com/Amoifr "Amoifr (2 commits)")[![nikophil](https://avatars.githubusercontent.com/u/10139766?v=4)](https://github.com/nikophil "nikophil (2 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (2 commits)")[![OskarStark](https://avatars.githubusercontent.com/u/995707?v=4)](https://github.com/OskarStark "OskarStark (2 commits)")[![priyadi](https://avatars.githubusercontent.com/u/1102197?v=4)](https://github.com/priyadi "priyadi (2 commits)")[![wouterj](https://avatars.githubusercontent.com/u/749025?v=4)](https://github.com/wouterj "wouterj (2 commits)")[![bonroyage](https://avatars.githubusercontent.com/u/4411748?v=4)](https://github.com/bonroyage "bonroyage (1 commits)")[![verfriemelt-dot-org](https://avatars.githubusercontent.com/u/1136869?v=4)](https://github.com/verfriemelt-dot-org "verfriemelt-dot-org (1 commits)")[![vtsykun](https://avatars.githubusercontent.com/u/21358010?v=4)](https://github.com/vtsykun "vtsykun (1 commits)")[![yoeunes](https://avatars.githubusercontent.com/u/10859693?v=4)](https://github.com/yoeunes "yoeunes (1 commits)")

---

Tags

clonecomponentconstructdeep-cloneexporthydrateinstantiatelazy-loadingphpproxyserializesymfonysymfony-componentproxylazy loadinginstantiateserializeexportcloneconstructhydrate

### Embed Badge

![Health badge](/badges/symfony-var-exporter/health.svg)

```
[![Health](https://phpackages.com/badges/symfony-var-exporter/health.svg)](https://phpackages.com/packages/symfony-var-exporter)
```

###  Alternatives

[ocramius/proxy-manager

A library providing utilities to generate, instantiate and generally operate with Object Proxies

5.0k82.4M230](/packages/ocramius-proxy-manager)[doctrine/instantiator

A small, lightweight utility to instantiate objects in PHP without invoking their constructors

11.0k853.3M335](/packages/doctrine-instantiator)[myclabs/deep-copy

Create deep copies (clones) of your objects

8.9k849.8M169](/packages/myclabs-deep-copy)[friendsofphp/proxy-manager-lts

Adding support for a wider range of PHP versions to ocramius/proxy-manager

1.2k139.1M104](/packages/friendsofphp-proxy-manager-lts)[fideloper/proxy

Set trusted proxies for Laravel

7.3k174.4M559](/packages/fideloper-proxy)[riimu/kit-phpencoder

Highly customizable alternative to var\_export for PHP code generation

717.8M32](/packages/riimu-kit-phpencoder)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
