Arquivos
hhvm/hphp/test/slow/array_iterator/array-traversable.php
T
Drew Paroski 89765cd4f2 Make arrays implement Traversable and KeyedTraversable
This diff changes HHVM so that arrays are considered to implement the
Traversable and KeyedTraversable interfaces (which have no methods).

The idea is that these interfaces will be useful for parameter type
constraints for PHP code that wants to be compatible with both arrays and
collections (and possibly other objects that implement these interfaces).
2013-05-20 13:52:32 -07:00

32 linhas
620 B
PHP

<?php
interface IFoo {}
function trav(Traversable $x) {
echo "Traversable " . $x . " \n";
var_dump($x);
}
function ktrav(KeyedTraversable $x) {
echo "KeyedTraversable " . $x . " \n";
var_dump($x);
}
function ind(Indexish $x) {
echo "Indexish " . $x . " \n";
var_dump($x);
}
function ifoo(IFoo $x) {
echo "IFoo " . $x . " \n";
var_dump($x);
}
function main() {
$arr = array();
var_dump($arr instanceof Traversable);
var_dump($arr instanceof KeyedTraversable);
var_dump($arr instanceof Indexish);
var_dump($arr instanceof IFoo);
trav($arr);
ktrav($arr);
ind($arr);
ifoo($arr);
}
main();