3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?hh //strict interface Comparer<T> { public function __invoke(T $a, T $b): int; } class Box<T> { public T $property; public function __construct(T $property){ $this->property = $property; } } class BoxComparer<T> implements Comparer<Box<T>> { public function __invoke(Box<T> $a, Box<T> $b): int { if ($a->property < $b->property) { return -1; } elseif ($b->property < $a->property) { return 1; } else { return 0; } } } class Sorter<T> { public function __invoke(Collection<T> $items, (function(T, T): int) $comparer): void { echo __METHOD__, PHP_EOL; } } $collection = Vector {new Box(1), new Box(2)}; $sorter = new Sorter(); $sorter($collection, new BoxComparer()); $sorter($collection, 1);
based on uW8OE
Output for 5.4.34 - 5.4.35
Parse error: syntax error, unexpected 'interface' (T_INTERFACE) in /in/8sjT2 on line 3
Process exited with code 255.
Output for 5.4.0 - 5.4.32
<?hh //strict interface Comparer<T> { public function __invoke(T $a, T $b): int; } class Box<T> { public T $property; public function __construct(T $property){ $this->property = $property; } } class BoxComparer<T> implements Comparer<Box<T>> { public function __invoke(Box<T> $a, Box<T> $b): int { if ($a->property < $b->property) { return -1; } elseif ($b->property < $a->property) { return 1; } else { return 0; } } } class Sorter<T> { public function __invoke(Collection<T> $items, (function(T, T): int) $comparer): void { echo __METHOD__, PHP_EOL; } } $collection = Vector {new Box(1), new Box(2)}; $sorter = new Sorter(); $sorter($collection, new BoxComparer()); $sorter($collection, 1);