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); $a = array($o1, $o2, $o3); foreach($a as $o){ sort($a->o->distance); } var_dump($a);
based on DLjVg
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Warning: Attempt to modify property of non-object in /in/4YN63 on line 22 Warning: sort() expects parameter 1 to be array, null given in /in/4YN63 on line 22 Warning: Attempt to modify property of non-object in /in/4YN63 on line 22 Warning: sort() expects parameter 1 to be array, null given in /in/4YN63 on line 22 Warning: Attempt to modify property of non-object in /in/4YN63 on line 22 Warning: sort() expects parameter 1 to be array, null given in /in/4YN63 on line 22 array(3) { [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) } }
Output for hhvm-3.10.0 - 3.12.0
Warning: Invalid operand type was used: sort expects array(s) or collection(s) in /in/4YN63 on line 22 Warning: Invalid operand type was used: sort expects array(s) or collection(s) in /in/4YN63 on line 22 Warning: Invalid operand type was used: sort expects array(s) or collection(s) in /in/4YN63 on line 22 array(3) { [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) } }
Output for 5.0.0 - 5.2.17
Warning: sort() expects parameter 1 to be array, null given in /in/4YN63 on line 22 Warning: sort() expects parameter 1 to be array, null given in /in/4YN63 on line 22 Warning: sort() expects parameter 1 to be array, null given in /in/4YN63 on line 22 array(3) { [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) } }
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/4YN63 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/4YN63 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/4YN63 on line 4
Process exited with code 255.