3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Auto{ private $farba; private $nazov; public function __construct($paFarba, $paNazov){ $this->farba = $paFarba; $this->nazov = $paNazov; } public function getFarba(){ return $this->farba; } public function getNazov(){ return $this->nazov; } public function __toString(){ return "Auto: {$this->nazov} {$this->farba}"; } } function compareNazov($obj1, $obj2){ return strcmp($obj1->nazov, $obj2->nazov); } function compareFarba($obj1, $obj2){ return strcmp($obj1->farba, $obj2->farba); } $cars = array(new Auto("Zlta", "Volvo"), new Auto("Cervena", "Skoda"), new Auto("Zelena", "Octavia")); $car = new Auto("Fialova", "Toyota"); $length = count($cars); for ($i = 0; $i < $length; $i++){ echo $cars[$i]; echo "<br>"; } usort($cars, "compareNazov"); for ($i = 0; $i < $length; $i++){ echo $cars[$i]; echo "<br>"; } ?>
based on ViOvB
Output for 7.0.0 - 7.2.0
Auto: Volvo Zlta<br>Auto: Skoda Cervena<br>Auto: Octavia Zelena<br> Fatal error: Uncaught Error: Cannot access private property Auto::$nazov in /in/voWcA:27 Stack trace: #0 [internal function]: compareNazov(Object(Auto), Object(Auto)) #1 /in/voWcA(42): usort(Array, 'compareNazov') #2 {main} thrown in /in/voWcA on line 27
Process exited with code 255.
Output for 5.3.19 - 5.6.28
Auto: Volvo Zlta<br>Auto: Skoda Cervena<br>Auto: Octavia Zelena<br> Fatal error: Cannot access private property Auto::$nazov in /in/voWcA on line 27
Process exited with code 255.