Skip to content

Conversation

@yottalogical
Copy link
Contributor

@yottalogical yottalogical commented Sep 16, 2025

This adds type template generics to iterator_to_array and SeekableIterator. This allows static analyzers to automatically determine the key and value types of the array returned by iterator_to_array, such as in this example:

<?php

/** @var SeekableIterator<int, string> */
$iterator = new ArrayIterator(['a', 'b', 'c']);

$array = iterator_to_array($iterator);

// Static analyzers know the types of $key and $value
foreach ($array as $key => $value) {
	echo "$key: $value" . PHP_EOL;
}

@isfedorov isfedorov merged commit ab31123 into JetBrains:master Sep 18, 2025
13 checks passed
@yottalogical yottalogical deleted the iterator_to_array-generics branch September 18, 2025 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants