3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php abstract class AHeap extends SplHeap { public function __construct($i) { foreach ($i as $obj) { $this->insert($obj); } } } class KeySort extends AHeap { public function compare($val1, $val2) { if ($val1->key == $val2->key) return 0; if ($val1->key > $val2->key){ return -1; } else { return 1; } } } class ValueSort extends AHeap { public function compare($val1, $val2) { if ($val1->value == $val2->value) return 0; if ($val1->value < $val2->value){ return -1; } else { return 1; } } } $array = array( (object) array('key' => 0, 'value' => 'z'), (object) array('key' => 0, 'value' => 'a'), (object) array('key' => 2, 'value' => 'y'), (object) array('key' => 3, 'value' => 'b'), ); $heap = new ValueSort($array); foreach ($heap as $val) { echo $val->key . ' - ' . $val->value . PHP_EOL; }
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
0 - z 2 - y 3 - b 0 - a
Output for 5.0.0 - 5.2.17
Fatal error: Class 'SplHeap' not found in /in/1CH1j on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CLASS in /in/1CH1j on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_CLASS in /in/1CH1j on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/1CH1j on line 3
Process exited with code 255.