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
Nicolas Grekas 8ea7c26326 Merge branch '5.0'
* 5.0: (27 commits)
  Fix versions
  [Security/Http] Allow setting cookie security settings for delete_cookies
  [DI] fix generating TypedReference from PriorityTaggedServiceTrait
  [FrameworkBundle] revert to legacy wiring of the session when circular refs are detected
  bumped Symfony version to 3.4.40
  updated VERSION for 3.4.39
  update CONTRIBUTORS for 3.4.39
  updated CHANGELOG for 3.4.39
  [DomCrawler] Fix BC break in assertions breaking Panther
  [BrowserKit] fixed missing post request parameters in file uploads
  update Italian translation
  [Validator] Add missing Hungarian translations
  [Validator] Add the missing translations for the Arabic (ar) locale
  [Validator] Add missing vietnamese translations
  [Console] Fix OutputStream for PHP 7.4
  add missing gitattributes for phpunit-bridge
  add German translations
  Bump Symfony version to 5.0.7
  Update VERSION for 5.0.6
  Update CHANGELOG for 5.0.6
  ...
2020-03-30 13:43:41 +02:00
..
Exception [VarExporter] throw component-specific exceptions 2018-09-10 10:23:43 +02:00
Internal Leverage PHP8's get_debug_type() 2020-03-16 17:46:21 +01:00
Tests Merge branch '4.4' 2019-11-13 08:42:48 +01:00
.gitattributes add missing gitattributes for phpunit-bridge 2020-03-27 17:54:36 +01: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 Leverage PHP8's get_debug_type() 2020-03-16 17:46:21 +01:00
Instantiator.php Replace @return annotation by return type in final classes 2019-06-23 00:57:33 +02:00
LICENSE Update year in license files 2020-01-01 12:51:43 +01:00
phpunit.xml.dist Merge branch '4.1' 2018-11-11 20:52:12 +01:00
README.md Fix link to documentation 2019-06-22 10:17:17 +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