This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/VarExporter
2018-09-08 20:19:57 +02:00
..
Internal [VarExporter] minor CS tweak 2018-09-08 20:19:57 +02:00
Tests [VarExporter] fix exporting instances of final classes that extend internal ones 2018-09-08 19:59:25 +02:00
.gitignore [VarExporter] a new component to serialize values to plain PHP code 2018-08-27 18:34:07 +02:00
CHANGELOG.md [VarExporter] a new component to serialize values to plain PHP code 2018-08-27 18:34:07 +02:00
composer.json [VarExporter] a new component to serialize values to plain PHP code 2018-08-27 18:34:07 +02:00
LICENSE [VarExporter] a new component to serialize values to plain PHP code 2018-08-27 18:34:07 +02:00
phpunit.xml.dist [VarExporter] a new component to serialize values to plain PHP code 2018-08-27 18:34:07 +02:00
README.md [VarExporter] a new component to serialize values to plain PHP code 2018-08-27 18:34:07 +02:00
VarExporter.php [VarExporter] optimize dumped code in time and space 2018-09-03 11:21:37 +02:00

VarExporter Component

The VarExporter component 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).

The reason to use this component vs serialize() or 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 ReflectionException 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 https://bugs.php.net/76737).

Resources