summaryrefslogtreecommitdiff
path: root/vendor/doctrine/collections/docs/en/serialization.rst
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/collections/docs/en/serialization.rst')
-rw-r--r--vendor/doctrine/collections/docs/en/serialization.rst29
1 files changed, 29 insertions, 0 deletions
diff --git a/vendor/doctrine/collections/docs/en/serialization.rst b/vendor/doctrine/collections/docs/en/serialization.rst
new file mode 100644
index 0000000..be53d6e
--- /dev/null
+++ b/vendor/doctrine/collections/docs/en/serialization.rst
@@ -0,0 +1,29 @@
1Serialization
2=============
3
4Using (un-)serialize() on a collection is not a supported use-case
5and may break when changes on the collection's internals happen in the future.
6If a collection needs to be serialized, use ``toArray()`` and reconstruct
7the collection manually.
8
9.. code-block:: php
10
11 $collection = new ArrayCollection([1, 2, 3]);
12 $serialized = serialize($collection->toArray());
13
14A reconstruction is also necessary when the collection contains objects with
15infinite recursion of dependencies like in this ``json_serialize()`` example:
16
17.. code-block:: php
18
19 $foo = new Foo();
20 $bar = new Bar();
21
22 $foo->setBar($bar);
23 $bar->setFoo($foo);
24
25 $collection = new ArrayCollection([$foo]);
26 $json = json_serialize($collection->toArray()); // recursion detected
27
28Serializer libraries can be used to create the serialization-output to prevent
29errors.