Skip to content

Commit b01a241

Browse files
committed
minor symfony#14729 [DependencyInjection] Fix possible error in example code (sp1ker)
This PR was submitted for the 5.x branch but it was merged into the 4.4 branch instead. Discussion ---------- [DependencyInjection] Fix possible error in example 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 of `Traversable`. <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `5.x` for features of unreleased versions). --> Commits ------- 74d460e Fix possible error code
2 parents ee18ef9 + 74d460e commit b01a241

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

service_container/tags.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ array element. For example, to retrieve the ``handler_two`` handler::
798798
{
799799
public function __construct(iterable $handlers)
800800
{
801-
$handlers = iterator_to_array($handlers);
801+
$handlers = $handlers instanceof \Traversable ? iterator_to_array($handlers) : $handlers;
802802

803803
$handlerTwo = $handlers['handler_two'];
804804
}

0 commit comments

Comments
 (0)