3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Box { private $x; private $y; private $z; public function __construct($x, $y, $z) { $this->x = $x; $this->y = $y; $this->z = $z; } public function getX() { return $this->x; } public function getY() { return $this->y; } public function getZ() { return $this->z; } public function __toString() { return "[{$this->x}, {$this->y}, {$this->z}]"; } public function maxRozmer() { return max([$this->x, $this->y, $this->z]); } } //find max rozmer function cmp(Box $a, Box $b) : int { if($a->maxRozmer() == $b->maxRozmer()) { return 0; } return ($a->maxRozmer() > $b->maxRozmer()) ? -1 : 1; } $boxes = [ new Box(7,7,4), new Box(101,1,2), new Box(5,20,1), ]; $result = usort($boxes, "cmp"); print_r($result); print_r($boxes);
Output for hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.2.6
1Array ( [0] => Box Object ( [x:Box:private] => 101 [y:Box:private] => 1 [z:Box:private] => 2 ) [1] => Box Object ( [x:Box:private] => 5 [y:Box:private] => 20 [z:Box:private] => 1 ) [2] => Box Object ( [x:Box:private] => 7 [y:Box:private] => 7 [z:Box:private] => 4 ) )
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected ':', expecting '{' in /in/vahpl on line 37
Process exited with code 255.