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", -1)); } 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 : $this; } public static function maxValDirection($moves, $board, $player, $pos){ $best = Move::initializeEmpty(); foreach($moves as $m){ $m->setValue($board, $player, $pos); $best = $m->compare($best); } return $best; } public function setValue($board, $player, $pos){ echo "0"; if ($board[$y][$x] != "-") $this->value = -1; else $this->value = 1; } } define("MAXSIZE", 100); echo MAXSIZE; define("ABCD", 100); echo ABCD; define(P1, "r"); define(P2, "l"); define(WALL, "#"); function nextMove($player,$pos,$board){ $moves = array(); array_push($moves, new Move(array($pos[0] - 1, $pos[1]), "UP", -1)); array_push($moves, new Move(array($pos[0] + 1, $pos[1]), "DOWN", -1)); array_push($moves, new Move(array($pos[0], $pos[1] - 1), "LEFT", -1)); array_push($moves, new Move(array($pos[0], $pos[1] + 1), "RIGHT", -1)); return Move::maxValDirection($moves, $board, $player, $pos)->direction; } $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.4, 8.3.6
100100 Fatal error: Uncaught Error: Undefined constant "P1" in /in/kckUc:46 Stack trace: #0 {main} thrown in /in/kckUc on line 46
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 100100 Fatal error: Uncaught Error: Undefined constant "P1" in /in/kckUc:46 Stack trace: #0 {main} thrown in /in/kckUc on line 46
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
100100 Warning: Use of undefined constant P1 - assumed 'P1' (this will throw an Error in a future version of PHP) in /in/kckUc on line 46 Warning: Use of undefined constant P2 - assumed 'P2' (this will throw an Error in a future version of PHP) in /in/kckUc on line 47 Warning: Use of undefined constant WALL - assumed 'WALL' (this will throw an Error in a future version of PHP) in /in/kckUc on line 48 0 Notice: Undefined variable: y in /in/kckUc on line 34 Notice: String offset cast occurred in /in/kckUc on line 34 Notice: Uninitialized string offset: 0 in /in/kckUc on line 34 Notice: Undefined variable: x in /in/kckUc on line 34 Notice: String offset cast occurred in /in/kckUc on line 34 Notice: Uninitialized string offset: 0 in /in/kckUc on line 34 0 Notice: Undefined variable: y in /in/kckUc on line 34 Notice: String offset cast occurred in /in/kckUc on line 34 Notice: Uninitialized string offset: 0 in /in/kckUc on line 34 Notice: Undefined variable: x in /in/kckUc on line 34 Notice: String offset cast occurred in /in/kckUc on line 34 Notice: Uninitialized string offset: 0 in /in/kckUc on line 34 Move Object ( [direction] => RIGHT [value] => -1 [x] => 1 [y] => 0 )
Output for 7.3.32 - 7.3.33
100100 Warning: Use of undefined constant P1 - assumed 'P1' (this will throw an Error in a future version of PHP) in /in/kckUc on line 46 Warning: Use of undefined constant P2 - assumed 'P2' (this will throw an Error in a future version of PHP) in /in/kckUc on line 47 Warning: Use of undefined constant WALL - assumed 'WALL' (this will throw an Error in a future version of PHP) in /in/kckUc on line 48 00Move Object ( [direction] => RIGHT [value] => -1 [x] => 1 [y] => 0 )
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20
100100 Notice: Use of undefined constant P1 - assumed 'P1' in /in/kckUc on line 46 Notice: Use of undefined constant P2 - assumed 'P2' in /in/kckUc on line 47 Notice: Use of undefined constant WALL - assumed 'WALL' in /in/kckUc on line 48 0 Notice: Undefined variable: y in /in/kckUc on line 34 Notice: String offset cast occurred in /in/kckUc on line 34 Notice: Uninitialized string offset: 0 in /in/kckUc on line 34 Notice: Undefined variable: x in /in/kckUc on line 34 Notice: String offset cast occurred in /in/kckUc on line 34 Notice: Uninitialized string offset: 0 in /in/kckUc on line 34 0 Notice: Undefined variable: y in /in/kckUc on line 34 Notice: String offset cast occurred in /in/kckUc on line 34 Notice: Uninitialized string offset: 0 in /in/kckUc on line 34 Notice: Undefined variable: x in /in/kckUc on line 34 Notice: String offset cast occurred in /in/kckUc on line 34 Notice: Uninitialized string offset: 0 in /in/kckUc on line 34 Move Object ( [direction] => RIGHT [value] => -1 [x] => 1 [y] => 0 )

preferences:
151.46 ms | 404 KiB | 183 Q