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
Fabien Potencier 7e2fbe13c8 Merge branch '4.2'
* 4.2:
  fixed bad merge
  Show more accurate message in profiler when missing stopwatch
  CS Fixes: Not double split with one array argument
  [Serializer] Add default object class resolver
  Remove redundant animation prefixes
  Remove redundant `box-sizing` prefixes
  [VarExporter] support PHP7.4 __serialize & __unserialize
  Rework firewall access denied rule
  MetadataAwareNameConverter: Do not assume that property names are strings
  [VarExporter] fix exporting classes with private constructors
  fixed CS
  Fix missing $extraDirs when open_basedir returns
2019-04-10 21:42:49 +02:00
..
Exception [VarExporter] throw component-specific exceptions 2018-09-10 10:23:43 +02:00
Internal [VarExporter] support PHP7.4 __serialize & __unserialize 2019-04-09 22:09:28 +02:00
Tests [VarExporter] support PHP7.4 __serialize & __unserialize 2019-04-09 22:09:28 +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 updated version to 4.3 2018-11-26 17:19:01 +01:00
Instantiator.php [VarExporter] support PHP7.4 __serialize & __unserialize 2019-04-09 22:09:28 +02:00
LICENSE update years in license files 2019-01-03 10:09:06 +01:00
phpunit.xml.dist Merge branch '4.1' 2018-11-11 20:52:12 +01:00
README.md [VarExporter] support PHP7.4 __serialize & __unserialize 2019-04-09 22:09:28 +02:00
VarExporter.php [VarExporter] support PHP7.4 __serialize & __unserialize 2019-04-09 22:09:28 +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, __serialize, __unserialize).

It also provides an instantiator that allows creating and populating objects without calling their constructor nor any other methods.

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 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 https://bugs.php.net/76737).

Resources