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.1.1(6d ago)2.1k407.7M↓23.8%620MITPHPPHP &gt;=8.4.1

Since Oct 29Pushed 6d 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.2 Synced 2d ago

READMEChangelog (10)Dependencies (16)Versions (278)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())`;
- `ProxyHelper::generateLazyProxy()` generates lazy-loading decorators for abstract or internal classes and for interfaces (use native lazy objects for regular concrete classes).

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.
```

Sponsor
-------

[](#sponsor)

This package is looking for a [backer](https://symfony.com/backers).

Help Symfony by [sponsoring](https://symfony.com/sponsor) its development!

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

85

—

ExcellentBetter than 100% of packages

Maintenance99

Actively maintained with recent releases

Popularity78

Solid adoption and visibility

Community49

Growing community involvement

Maturity99

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 63.3% 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 ~0 days

Total

278

Last Release

6d ago

Major Versions

v7.4.8 → v8.0.82026-03-30

v6.4.37 → v7.4.92026-04-18

v7.4.9 → v8.0.92026-04-18

v6.4.42 → 7.4.x-dev2026-06-27

v7.4.14 → 8.0.x-dev2026-06-27

PHP version history (10 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

v8.1.0-BETA1PHP &gt;=8.4.1

### 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 (315 commits)")[![fabpot](https://avatars.githubusercontent.com/u/47313?v=4)](https://github.com/fabpot "fabpot (67 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)")[![cheack](https://avatars.githubusercontent.com/u/668493?v=4)](https://github.com/cheack "cheack (1 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)")

---

Tags

clonecomponentconstructdeep-cloneexporthydrateinstantiatelazy-loadingphpproxyserializesymfonysymfony-componentproxylazy loadinginstantiateserializeexportcloneconstructhydratedeep clone

### 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

[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k455.6M9.6k](/packages/symfony-dependency-injection)[symfony/config

Helps you find, load, combine, autofill and validate configuration values of any kind

4.3k479.6M8.4k](/packages/symfony-config)[ocramius/proxy-manager

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

5.0k83.1M242](/packages/ocramius-proxy-manager)[symfony/service-contracts

Generic abstractions related to writing services

2.6k914.7M605](/packages/symfony-service-contracts)[symfony/options-resolver

Provides an improved replacement for the array\_replace PHP function

3.2k525.7M2.0k](/packages/symfony-options-resolver)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M386](/packages/easycorp-easyadmin-bundle)

PHPackages © 2026

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