3v4l.org

run code in 300+ PHP versions simultaneously
<?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());
Output for git.master, git.master_jit, rfc.property-hooks
<?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());

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
26.78 ms | 402 KiB | 8 Q