From 74d460ec5b99731e230522f356016fbc2bd7e500 Mon Sep 17 00:00:00 2001 From: Evgeniy Gavrilov Date: Mon, 21 Dec 2020 22:40:36 +0300 Subject: [PATCH] Fix possible error code Pseudo-type `iterable` accepts any `array` or `object` implementing the `Traversable` interface. Constructor will be crashed when we try to pass array instead of `Traversable` and use `iterator_to_array`. `iterator_to_array` dont work with arrays. Then if always passing `Traversable` we could write like this: ```php public function __construct(Traversable $handlers) ``` or check instance on `Traversable`. --- service_container/tags.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service_container/tags.rst b/service_container/tags.rst index 6783ef06d4e..76d4cb9792e 100644 --- a/service_container/tags.rst +++ b/service_container/tags.rst @@ -798,7 +798,7 @@ array element. For example, to retrieve the ``handler_two`` handler:: { public function __construct(iterable $handlers) { - $handlers = iterator_to_array($handlers); + $handlers = $handlers instanceof \Traversable ? iterator_to_array($handlers) : $handlers; $handlerTwo = $handlers['handler_two']; }