3v4l.org

run code in 300+ PHP versions simultaneously
<?php function reOrderByProvider( MyObject $actualObject, MyObject $nextObject ) { $weights = [ null => 100, 'gmail' => 50, 'hotmail' => 25, ]; $provider = $actualObject->getProvider(); $actualObjectWeight = array_key_exists($provider, $weights) ? $weights[$provider] : 0; $provider = $nextObject->getProvider(); $nextObjectWeight = array_key_exists($provider, $weights) ? $weights[$provider] : 0; return $nextObjectWeight - $actualObjectWeight; } class MyObject { protected $provider; protected $name; function getProvider() { return $this->provider; } function __construct($name, $provider = NULL) { $this->name = $name; $this->provider = $provider; } } $items = [ new MyObject('Second', 'gmail'), new MyObject('First'), new MyObject('Fourth', 'provider42'), new MyObject('Third', 'hotmail'), new MyObject('5th', 'yaprovider'), ]; usort($items, 'reOrderByProvider'); print_r($items);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UWOqX
function name:  (null)
number of ops:  33
compiled vars:  !0 = $items
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   NEW                                              $1      'MyObject'
          1        SEND_VAL_EX                                              'Second'
          2        SEND_VAL_EX                                              'gmail'
          3        DO_FCALL                                      0          
          4        INIT_ARRAY                                       ~3      $1
   37     5        NEW                                              $4      'MyObject'
          6        SEND_VAL_EX                                              'First'
          7        DO_FCALL                                      0          
          8        ADD_ARRAY_ELEMENT                                ~3      $4
   38     9        NEW                                              $6      'MyObject'
         10        SEND_VAL_EX                                              'Fourth'
         11        SEND_VAL_EX                                              'provider42'
         12        DO_FCALL                                      0          
         13        ADD_ARRAY_ELEMENT                                ~3      $6
   39    14        NEW                                              $8      'MyObject'
         15        SEND_VAL_EX                                              'Third'
         16        SEND_VAL_EX                                              'hotmail'
         17        DO_FCALL                                      0          
         18        ADD_ARRAY_ELEMENT                                ~3      $8
   40    19        NEW                                              $10     'MyObject'
         20        SEND_VAL_EX                                              '5th'
         21        SEND_VAL_EX                                              'yaprovider'
         22        DO_FCALL                                      0          
         23        ADD_ARRAY_ELEMENT                                ~3      $10
   35    24        ASSIGN                                                   !0, ~3
   43    25        INIT_FCALL                                               'usort'
         26        SEND_REF                                                 !0
         27        SEND_VAL                                                 'reOrderByProvider'
         28        DO_ICALL                                                 
   44    29        INIT_FCALL                                               'print_r'
         30        SEND_VAR                                                 !0
         31        DO_ICALL                                                 
         32      > RETURN                                                   1

Function reorderbyprovider:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
Branch analysis from position: 21
filename:       /in/UWOqX
function name:  reOrderByProvider
number of ops:  26
compiled vars:  !0 = $actualObject, !1 = $nextObject, !2 = $weights, !3 = $provider, !4 = $actualObjectWeight, !5 = $nextObjectWeight
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        ASSIGN                                                   !2, <array>
   12     3        INIT_METHOD_CALL                                         !0, 'getProvider'
          4        DO_FCALL                                      0  $7      
          5        ASSIGN                                                   !3, $7
   13     6        ARRAY_KEY_EXISTS                                         !3, !2
          7      > JMPZ                                                     ~9, ->11
          8    >   FETCH_DIM_R                                      ~10     !2, !3
          9        QM_ASSIGN                                        ~11     ~10
         10      > JMP                                                      ->12
         11    >   QM_ASSIGN                                        ~11     0
         12    >   ASSIGN                                                   !4, ~11
   14    13        INIT_METHOD_CALL                                         !1, 'getProvider'
         14        DO_FCALL                                      0  $13     
         15        ASSIGN                                                   !3, $13
   15    16        ARRAY_KEY_EXISTS                                         !3, !2
         17      > JMPZ                                                     ~15, ->21
         18    >   FETCH_DIM_R                                      ~16     !2, !3
         19        QM_ASSIGN                                        ~17     ~16
         20      > JMP                                                      ->22
         21    >   QM_ASSIGN                                        ~17     0
         22    >   ASSIGN                                                   !5, ~17
   17    23        SUB                                              ~19     !5, !4
         24      > RETURN                                                   ~19
   18    25*     > RETURN                                                   null

End of function reorderbyprovider

Class MyObject:
Function getprovider:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UWOqX
function name:  getProvider
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   FETCH_OBJ_R                                      ~0      'provider'
          1      > RETURN                                                   ~0
   26     2*     > RETURN                                                   null

End of function getprovider

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UWOqX
function name:  __construct
number of ops:  7
compiled vars:  !0 = $name, !1 = $provider
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   29     2        ASSIGN_OBJ                                               'name'
          3        OP_DATA                                                  !0
   30     4        ASSIGN_OBJ                                               'provider'
          5        OP_DATA                                                  !1
   32     6      > RETURN                                                   null

End of function __construct

End of class MyObject.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.95 ms | 1016 KiB | 15 Q