89765cd4f2
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).
32 linhas
620 B
PHP
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();
|
|
|