3v4l.org

run code in 300+ PHP versions simultaneously
<?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 />"; } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 23
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 23
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/Gi6EB
function name:  (null)
number of ops:  25
compiled vars:  !0 = $familyId, !1 = $family, !2 = $member
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   ASSIGN                                                   !0, 5
   52     1        NEW                                              $4      'family'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $4
   53     5        INIT_METHOD_CALL                                         !1, 'open'
          6        DO_FCALL                                      0          
   56     7        INIT_METHOD_CALL                                         !1, 'sortMembers'
          8        SEND_VAL_EX                                              <array>
          9        DO_FCALL                                      0          
   58    10        FETCH_OBJ_R                                      ~9      !1, 'members'
         11      > FE_RESET_R                                       $10     ~9, ->23
         12    > > FE_FETCH_R                                               $10, !2, ->23
   60    13    >   FETCH_OBJ_R                                      ~11     !2, 'firstName'
         14        CONCAT                                           ~12     ~11, '+-+'
         15        FETCH_OBJ_R                                      ~13     !2, 'age'
         16        CONCAT                                           ~14     ~12, ~13
         17        CONCAT                                           ~15     ~14, '+-+'
         18        FETCH_OBJ_R                                      ~16     !2, 'hairColor'
         19        CONCAT                                           ~17     ~15, ~16
         20        CONCAT                                           ~18     ~17, '%3Cbr+%2F%3E'
         21        ECHO                                                     ~18
   58    22      > JMP                                                      ->12
         23    >   FE_FREE                                                  $10
   62    24      > RETURN                                                   1

Class familyMember: [no user functions]
Class family:
Function _objsort:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 34
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
Branch analysis from position: 27
filename:       /in/Gi6EB
function name:  _objSort
number of ops:  36
compiled vars:  !0 = $a, !1 = $b, !2 = $i, !3 = $field, !4 = $direction, !5 = $diff
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      0
   22     3        FETCH_OBJ_R                                      ~6      'sortFields'
          4        FETCH_DIM_R                                      ~7      ~6, !2
          5        ASSIGN                                                   !3, ~7
   23     6        FETCH_OBJ_R                                      ~9      'sortDirections'
          7        FETCH_DIM_R                                      ~10     ~9, !2
          8        ASSIGN                                                   !4, ~10
   25     9        INIT_FCALL                                               'strnatcmp'
         10        FETCH_OBJ_R                                      ~12     'details'
         11        FETCH_DIM_R                                      ~13     ~12, !0
         12        FETCH_OBJ_R                                      ~14     ~13, !3
         13        SEND_VAL                                                 ~14
         14        FETCH_OBJ_R                                      ~15     'details'
         15        FETCH_DIM_R                                      ~16     ~15, !1
         16        FETCH_OBJ_R                                      ~17     ~16, !3
         17        SEND_VAL                                                 ~17
         18        DO_ICALL                                         $18     
         19        MUL                                              ~19     !4, $18
         20        ASSIGN                                                   !5, ~19
   26    21        IS_EQUAL                                         ~21     !5, 0
         22      > JMPZ_EX                                          ~21     ~21, ->27
         23    >   PRE_INC                                          ~23     !2
         24        FETCH_OBJ_IS                                     ~22     'sortFields'
         25        ISSET_ISEMPTY_DIM_OBJ                         0  ~24     ~22, ~23
         26        BOOL                                             ~21     ~24
         27    > > JMPZ                                                     ~21, ->34
   28    28    >   INIT_METHOD_CALL                                         '_objSort'
         29        SEND_VAR_EX                                              !0
         30        SEND_VAR_EX                                              !1
         31        SEND_VAR_EX                                              !2
         32        DO_FCALL                                      0  $25     
         33        ASSIGN                                                   !5, $25
   31    34    > > RETURN                                                   !5
   32    35*     > RETURN                                                   null

End of function _objsort

Function sortmembers:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 22
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 22
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/Gi6EB
function name:  sortMembers
number of ops:  36
compiled vars:  !0 = $sortFields, !1 = $i, !2 = $direction, !3 = $field
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   36     1        ASSIGN                                                   !1, 0
   37     2      > FE_RESET_R                                       $5      !0, ->22
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->22
          4    >   ASSIGN                                                   !3, ~6
   39     5        FETCH_OBJ_W                                      $8      'sortFields'
          6        ASSIGN_DIM                                               $8, !1
          7        OP_DATA                                                  !3
   40     8        IS_EQUAL                                                 !2, 'DESC'
          9      > JMPZ                                                     ~10, ->15
         10    >   FETCH_OBJ_W                                      $11     'sortDirections'
         11        ASSIGN_DIM                                       ~12     $11, !1
         12        OP_DATA                                                  -1
         13        QM_ASSIGN                                        ~13     ~12
         14      > JMP                                                      ->19
         15    >   FETCH_OBJ_W                                      $14     'sortDirections'
         16        ASSIGN_DIM                                       ~15     $14, !1
         17        OP_DATA                                                  1
         18        QM_ASSIGN                                        ~13     ~15
         19    >   FREE                                                     ~13
   41    20        PRE_INC                                                  !1
   37    21      > JMP                                                      ->3
         22    >   FE_FREE                                                  $5
   44    23        INIT_FCALL                                               'uksort'
         24        FETCH_OBJ_W                                      $17     'details'
         25        SEND_REF                                                 $17
         26        FETCH_THIS                                       ~18     
         27        INIT_ARRAY                                       ~19     ~18
         28        ADD_ARRAY_ELEMENT                                ~19     '_objSort'
         29        SEND_VAL                                                 ~19
         30        DO_ICALL                                                 
   46    31        ASSIGN_OBJ                                               'sortFields'
         32        OP_DATA                                                  <array>
   47    33        ASSIGN_OBJ                                               'sortDirections'
         34        OP_DATA                                                  <array>
   48    35      > RETURN                                                   null

End of function sortmembers

End of class family.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.36 ms | 1404 KiB | 17 Q