3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class familyMember { var $memberId; var $familyId; var $firstName; var $age; var $hairColor; // ... } class family { var $familyId; var $name; var $members = array(); // array of familyMember objects var $sortFields = array(); var $sortDirections = array(); // ... function _objSort(&$a, &$b, $i = 0) { $field = $this->sortFields[$i]; $direction = $this->sortDirections[$i]; $diff = strnatcmp($this->details[$a]->$field, $this->details[$b]->$field) * $direction; if ($diff == 0 && isset($this->sortFields[++$i])) { $diff = $this->_objSort($a, $b, $i); } return $diff; } function sortMembers($sortFields) { $i = 0; foreach ($sortFields as $field => $direction) { $this->sortFields[$i] = $field; $direction == "DESC" ? $this->sortDirections[$i] = -1 : $this->sortDirections[$i] = 1; $i++; } uksort($this->details, array($this, "_objSort")); $this->sortFields = array(); $this->sortDirections = array(); } } // open a family $familyId = 5; $family = new family($familyId); $family->open(); // this will also fetch all members // sort members by 3 fields $family->sortMembers(array("firstName" => "ASC", "age" => "DESC", "hairColor" => "ASC")); // output all family members foreach ($family->members as $member) { echo $member->firstName." - ".$member->age." - ".$member->hairColor."<br />"; } ?>
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Call to undefined method family::open() in /in/Gi6EB:53 Stack trace: #0 {main} thrown in /in/Gi6EB on line 53
Process exited with code 255.
Output for 5.3.21 - 5.6.28
Fatal error: Call to undefined method family::open() in /in/Gi6EB on line 53
Process exited with code 255.