iterator_count signature for iterables

From: Date: Tue, 26 Nov 2024 09:40:23 +0000
Subject: iterator_count signature for iterables
Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hello internals!

Currently, iterator_count has the following signature:

 iterator_count(Traversable|array $iterator): int

If we try to use iterable type and pass it to iterator_count function, we'd
get following static analysis error:

 Argument 1 of iterator_count expects Traversable|array<array-key, mixed>,
but iterable<int, list<string>> provided (see https://psalm.dev/004)
$start(iterator_count($chunks));

From what I know, iterable is just built-in compile time type alias
for array|Traversable
(https://www.php.net/manual/en/language.types.iterable.php)

I think it would make sense to change the signature of iterator_count to
accept iterable rather than array|Traversable so that static analysis tools
would pick it up better


Thread (5 messages)

« previous php.internals (#126051) next »