blob: 0ff2524f47478ab265c8c2f3e9cc5c1c68749557 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
--TEST--
Return type covariance works with generators
--FILE--
<?php
interface Collection extends IteratorAggregate {
function getIterator(): Iterator;
}
class SomeCollection implements Collection {
function getIterator(): Generator {
foreach ($this->data as $key => $value) {
yield $key => $value;
}
}
}
$some = new SomeCollection();
var_dump($some->getIterator());
--EXPECTF--
Fatal error: Declaration of SomeCollection::getIterator(): Generator must be compatible with Collection::getIterator(): Iterator in %sgenerators003.php on line 6
|