3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class AHeap extends SplHeap { public function __construct($i) { foreach ($i as $obj) { $this->insert($obj); } } } class KeySort extends AHeap { protected function compare(object $val1, $val2) { if ($val1->key == $val2->key) { if ($val1->value == $val2->value) { return 0; } if ($val1->value > $val2->value){ return -1; } else { return 1; } } if ($val1->key > $val2->key){ 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 KeySort($array); foreach ($heap as $val) { echo $val->key . ' - ' . $val->value . PHP_EOL; }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Declaration of KeySort::compare(object $val1, $val2) must be compatible with SplHeap::compare(mixed $value1, mixed $value2): int in /in/B3Aju on line 15
Process exited with code 255.
Output for 8.0.0 - 8.0.30
Fatal error: Declaration of KeySort::compare(object $val1, $val2) must be compatible with SplHeap::compare(mixed $value1, mixed $value2) in /in/B3Aju on line 15
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
0 - a 0 - z 2 - y 3 - b
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33
Fatal error: Uncaught TypeError: Argument 1 passed to KeySort::compare() must be an instance of object, instance of stdClass given in /in/B3Aju:15 Stack trace: #0 [internal function]: KeySort->compare(Object(stdClass), Object(stdClass)) #1 /in/B3Aju(8): SplHeap->insert(Object(stdClass)) #2 /in/B3Aju(46): AHeap->__construct(Array) #3 {main} thrown in /in/B3Aju on line 15
Process exited with code 255.
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Catchable fatal error: Argument 1 passed to KeySort::compare() must be an instance of object, instance of stdClass given in /in/B3Aju on line 15
Process exited with code 255.
Output for 5.2.3 - 5.2.17
Fatal error: Class 'SplHeap' not found in /in/B3Aju on line 3
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.2
<br /> <b>Fatal error</b>: Class 'SplHeap' not found in <b>/in/B3Aju</b> on line <b>3</b><br />
Process exited with code 255.
Output for 4.4.2 - 4.4.9
<br /> <b>Parse error</b>: syntax error, unexpected T_CLASS in <b>/in/B3Aju</b> on line <b>3</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
<br /> <b>Parse error</b>: parse error, unexpected T_CLASS in <b>/in/B3Aju</b> on line <b>3</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Parse error</b>: parse error in <b>/in/B3Aju</b> on line <b>3</b><br />
Process exited with code 255.

preferences:
312.42 ms | 401 KiB | 460 Q