3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Move { var $direction; var $value; var $x; var $y; public static function initializeEmpty(){ return (new Move(array(0, 0), "NONE", -2)); } public function __construct($pos, $direction, $value){ $this->y = $pos[0]; $this->x = $pos[1]; $this->value = $value; $this->direction = $direction; } public function compare($move){ return $move->value > $this->value ? $move->value : $this->value; } public static function maxValDirection($moves){ $best = Move::initializeEmpty(); print_r($best); print_r($moves); foreach($moves as $m){ print_r($move); $best = $move->compare($best); } return $best; } } $m1 = Move::initializeEmpty(); $m2 = new Move(array(0, 1), "RIGHT", 10); print_r(Move::maxValDirection(array($m1, $m2))); ?>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Move Object ( [direction] => NONE [value] => -2 [x] => 0 [y] => 0 ) Array ( [0] => Move Object ( [direction] => NONE [value] => -2 [x] => 0 [y] => 0 ) [1] => Move Object ( [direction] => RIGHT [value] => 10 [x] => 1 [y] => 0 ) ) Warning: Undefined variable $move in /in/qrUcQ on line 28 Warning: Undefined variable $move in /in/qrUcQ on line 29 Fatal error: Uncaught Error: Call to a member function compare() on null in /in/qrUcQ:29 Stack trace: #0 /in/qrUcQ(36): Move::maxValDirection(Array) #1 {main} thrown in /in/qrUcQ on line 29
Process exited with code 255.
Output for 7.0.5 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Move Object ( [direction] => NONE [value] => -2 [x] => 0 [y] => 0 ) Array ( [0] => Move Object ( [direction] => NONE [value] => -2 [x] => 0 [y] => 0 ) [1] => Move Object ( [direction] => RIGHT [value] => 10 [x] => 1 [y] => 0 ) ) Notice: Undefined variable: move in /in/qrUcQ on line 28 Notice: Undefined variable: move in /in/qrUcQ on line 29 Fatal error: Uncaught Error: Call to a member function compare() on null in /in/qrUcQ:29 Stack trace: #0 /in/qrUcQ(36): Move::maxValDirection(Array) #1 {main} thrown in /in/qrUcQ on line 29
Process exited with code 255.
Output for 7.3.32 - 7.3.33
Move Object ( [direction] => NONE [value] => -2 [x] => 0 [y] => 0 ) Array ( [0] => Move Object ( [direction] => NONE [value] => -2 [x] => 0 [y] => 0 ) [1] => Move Object ( [direction] => RIGHT [value] => 10 [x] => 1 [y] => 0 ) ) Fatal error: Uncaught Error: Call to a member function compare() on null in /in/qrUcQ:29 Stack trace: #0 /in/qrUcQ(36): Move::maxValDirection(Array) #1 {main} thrown in /in/qrUcQ on line 29
Process exited with code 255.
Output for 7.0.0 - 7.0.4
Move Object ( [direction] => NONE [value] => -2 [x] => 0 [y] => 0 ) Array ( [0] => Move Object ( [direction] => NONE [value] => -2 [x] => 0 [y] => 0 ) [1] => Move Object ( [direction] => RIGHT [value] => 10 [x] => 1 [y] => 0 ) ) Notice: Undefined variable: move in /in/qrUcQ on line 28 Notice: Undefined variable: move in /in/qrUcQ on line 29 Fatal error: Uncaught Error: Call to a member function compare() on unknown in /in/qrUcQ:29 Stack trace: #0 /in/qrUcQ(36): Move::maxValDirection(Array) #1 {main} thrown in /in/qrUcQ on line 29
Process exited with code 255.
Output for 5.6.0 - 5.6.38
Move Object ( [direction] => NONE [value] => -2 [x] => 0 [y] => 0 ) Array ( [0] => Move Object ( [direction] => NONE [value] => -2 [x] => 0 [y] => 0 ) [1] => Move Object ( [direction] => RIGHT [value] => 10 [x] => 1 [y] => 0 ) ) Notice: Undefined variable: move in /in/qrUcQ on line 28 Notice: Undefined variable: move in /in/qrUcQ on line 29 Fatal error: Call to a member function compare() on null in /in/qrUcQ on line 29
Process exited with code 255.
Output for 5.5.0 - 5.5.38
Move Object ( [direction] => NONE [value] => -2 [x] => 0 [y] => 0 ) Array ( [0] => Move Object ( [direction] => NONE [value] => -2 [x] => 0 [y] => 0 ) [1] => Move Object ( [direction] => RIGHT [value] => 10 [x] => 1 [y] => 0 ) ) Notice: Undefined variable: move in /in/qrUcQ on line 28 Notice: Undefined variable: move in /in/qrUcQ on line 29 Fatal error: Call to a member function compare() on a non-object in /in/qrUcQ on line 29
Process exited with code 255.

preferences:
219.98 ms | 402 KiB | 294 Q