3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class GeoCoder { protected $latitude; protected $longitude; public $distance; public function __construct($lat,$long,$dist) { $this->latitude = $lat; $this->longitude = $long; $this->distance = $dist; } } $o1 = new GeoCoder(-22.43,-46.81,1500.00); $o2 = new GeoCoder(-22.42,-46.82,1740.00); $o3 = new GeoCoder(-21.43,-46.80,152.00); $nu = null; if ($o1->distance > $o2->distance) { $nu[] = $o2; $nu[] = $o1; } else { $nu[] = $o1; $nu[] = $o2; } if ($o2->distance > $o3->distance) { $nu[] = $o3; $nu[] = $o2; } else { $nu[] = $o2; $nu[] = $o3; } var_dump($nu);
based on t2G6R
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(4) { [0]=> object(GeoCoder)#1 (3) { ["latitude":protected]=> float(-22.43) ["longitude":protected]=> float(-46.81) ["distance"]=> float(1500) } [1]=> object(GeoCoder)#2 (3) { ["latitude":protected]=> float(-22.42) ["longitude":protected]=> float(-46.82) ["distance"]=> float(1740) } [2]=> object(GeoCoder)#3 (3) { ["latitude":protected]=> float(-21.43) ["longitude":protected]=> float(-46.8) ["distance"]=> float(152) } [3]=> object(GeoCoder)#2 (3) { ["latitude":protected]=> float(-22.42) ["longitude":protected]=> float(-46.82) ["distance"]=> float(1740) } }
Output for 5.0.0 - 5.2.17
array(4) { [0]=> object(GeoCoder)#1 (3) { ["latitude:protected"]=> float(-22.43) ["longitude:protected"]=> float(-46.81) ["distance"]=> float(1500) } [1]=> object(GeoCoder)#2 (3) { ["latitude:protected"]=> float(-22.42) ["longitude:protected"]=> float(-46.82) ["distance"]=> float(1740) } [2]=> object(GeoCoder)#3 (3) { ["latitude:protected"]=> float(-21.43) ["longitude:protected"]=> float(-46.8) ["distance"]=> float(152) } [3]=> object(GeoCoder)#2 (3) { ["latitude:protected"]=> float(-22.42) ["longitude:protected"]=> float(-46.82) ["distance"]=> float(1740) } }
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/qejOD on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/qejOD on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/qejOD on line 4
Process exited with code 255.