Rather than this, do:

```php
if (!is_array($extensions)) {
    $extensions = iterator_to_array($extensions);
}
```

then use `$extensions` rather than `$resultingExtensions` below.