From 03dc25d7b063a4c51a5ab59861df7ffbd61b7031 Mon Sep 17 00:00:00 2001 From: Alexander Strizhak Date: Fri, 5 Mar 2021 17:52:28 +0300 Subject: [PATCH] fix #314 --- doc/reference/annotations.rst | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/doc/reference/annotations.rst b/doc/reference/annotations.rst index f75ab3dbf..25e8419f8 100644 --- a/doc/reference/annotations.rst +++ b/doc/reference/annotations.rst @@ -690,22 +690,31 @@ keys of the array are not important. /** * @XmlList(inline = true, entry = "comment") */ - private $comments = array( - new Comment('Foo'), - new Comment('Bar'), - ); + private $comments = []; + + public function __construct(array $comments) + { + $this->comments = $comments; + } } class Comment { private $text; - public function __construct($text) + public function __construct(string $text) { $this->text = $text; } } + // usage + $post = new Post( + new Comment('Foo'), + new Comment('Bar'), + ); + $xml = $serializer->serialize($post, 'xml'); + Resulting XML: .. code-block :: xml