3v4l.org

run code in 300+ PHP versions simultaneously
<?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 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 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
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 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 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.40
Parse error: syntax error, unexpected ':', expecting '{' in /in/vahpl on line 37
Process exited with code 255.

preferences:
226.78 ms | 401 KiB | 291 Q