3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Pos { var $x; var $y; public function __construct($x, $y){ $this->x = $x; $this->y = $y; } public function distance($pos){ return (abs($this->x - $pos->x) + abs($this->y - $pos->y)); } } 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->y; $this->x = $pos->x; $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, $opPos){ $best = Move::initializeEmpty(); foreach($moves as $m){ $m->setValue($board, $player, $pos, $opPos); $best = $m->compare($best); } return $best; } public function setValue($board, $player, $pos, $opPos){ if ($board[$this->y][$this->x] != CLEAR) $this->value = -10; else{ $this-> value = 1; } } } define("CLEAR", chr(45)); define("P1", chr(114)); define("P2", chr(103)); define("WALL", chr(35)); function nextMove($player,$pos,$board, $opPos){ $moves = array(); array_push($moves, new Move(new Pos($pos->x, $pos->y - 1), "UP", -1)); array_push($moves, new Move(new Pos($pos->x, $pos->y + 1), "DOWN", -1)); array_push($moves, new Move(new Pos($pos->x - 1, $pos->y), "LEFT", -1)); array_push($moves, new Move(new Pos($pos->x + 1, $pos->y), "RIGHT", -1)); return Move::maxValDirection($moves, $board, $player, $pos, $opPos)->direction; } function getPlayerPos($player, $pos){ return ord($player) == ord(P1) ? new Pos($pos[1], $pos[0]) : new Pos($pos[3], $pos[2]); } $m1 = Move::initializeEmpty(); $m2 = new Move(array(0, 1), "RIGHT", 10); print_r(Move::maxValDirection(array($m1, $m2), "", "", "")); ?>
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Attempt to read property "y" on array in /in/EqDLZ on line 28 Warning: Attempt to read property "x" on array in /in/EqDLZ on line 29 Warning: Attempt to read property "y" on array in /in/EqDLZ on line 28 Warning: Attempt to read property "x" on array in /in/EqDLZ on line 29 Fatal error: Uncaught ArgumentCountError: Too few arguments to function Move::maxValDirection(), 4 passed in /in/EqDLZ on line 77 and exactly 5 expected in /in/EqDLZ:38 Stack trace: #0 /in/EqDLZ(77): Move::maxValDirection(Array, '', '', '') #1 {main} thrown in /in/EqDLZ on line 38
Process exited with code 255.

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:
52.16 ms | 401 KiB | 8 Q