<?php
// Return type iterable
interface IterableReturn
{
public function foo() : iterable;
}
// Return type array despite iterable is expected by interface
class ArrayReturn implements IterableReturn
{
public function foo() : array
{
return [];
}
}
dump((new ArrayReturn())->foo());
// Type hint array
interface ArrayHint
{
public function foo(array $a) : void;
}
// Type hint iterable despite array is expected by interface
class IterableHint implements ArrayHint
{
public function foo(iterable $a) : void
{
dump($a);
}
}
(new IterableHint())->foo(new EmptyIterator());