From bf6655a534a6775d30cafa67bd801276bda1d98d Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 13 Aug 2024 23:45:21 +0200 Subject: =?UTF-8?q?VERSION=200.2=20doctrine=20ORM=20et=20entit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../doctrine/collections/docs/en/serialization.rst | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 vendor/doctrine/collections/docs/en/serialization.rst (limited to 'vendor/doctrine/collections/docs/en/serialization.rst') 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 @@ +Serialization +============= + +Using (un-)serialize() on a collection is not a supported use-case +and may break when changes on the collection's internals happen in the future. +If a collection needs to be serialized, use ``toArray()`` and reconstruct +the collection manually. + +.. code-block:: php + + $collection = new ArrayCollection([1, 2, 3]); + $serialized = serialize($collection->toArray()); + +A reconstruction is also necessary when the collection contains objects with +infinite recursion of dependencies like in this ``json_serialize()`` example: + +.. code-block:: php + + $foo = new Foo(); + $bar = new Bar(); + + $foo->setBar($bar); + $bar->setFoo($foo); + + $collection = new ArrayCollection([$foo]); + $json = json_serialize($collection->toArray()); // recursion detected + +Serializer libraries can be used to create the serialization-output to prevent +errors. -- cgit v1.2.3