Skip to content

[DependencyInjection] RewindableGenerator returns an invalid traversable when IteratorArgument is empty  #22780

Closed
@meyerbaptiste

Description

@meyerbaptiste
Q A
Bug report? yes
Feature request? no
BC Break report? yes
RFC? no
Symfony version >= 3.3.0-BETA1

I have an IteratorArgument instance with an empty array as values (new IteratorArgument([])).
The PhpDumper instance transform it to a RewindableGenerator class like this:

new RewindableGenerator(function() {}, 0);

So, when I iterate on my RewindableGenerator instance, I get an error because function() {} is not a valid traversable:

Objects returned by Symfony\Component\DependencyInjection\Argument\RewindableGenerator::getIterator() must be traversable or implement interface Iterator

Currently the property_info service (PropertyInfoExtractor class) is impacted with getShortDescription and getLongDescription methods when the phpdocumentor/reflection-docblock package is not installed. See api-platform/core#1127.

I don't know what is the best way to fix this, but a solution is to generate an "empty" generator/iterator with the PhpDumper:

// PHP 7+
new RewindableGenerator(function () { yield from []; }, 0);

// PHP 5.1+
new RewindableGenerator(function () { return new \EmptyIterator(); }, 0);

WDYT?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions