3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Demo { public function __construct(private string $val) { } public function get_sku() { return [ 'abc' => 1, 'def' => 2, 'ghi' => 3, 'jkl' => 4, ][$this->val]; } } $cart = (object) [ 'cart_contents' => [ ['data' => new Demo('ghi')], ['data' => new Demo('def')], ['data' => new Demo('jkl')], ['data' => new Demo('abc')], ] ]; $skus = []; $items_to_sort = []; foreach ($cart->cart_contents as $item ) { $skus[] = $item['data']->get_sku(); } array_multisort($skus, $cart->cart_contents); var_export($cart->cart_contents);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 34
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 34
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/YE75c
function name:  (null)
number of ops:  45
compiled vars:  !0 = $cart, !1 = $skus, !2 = $items_to_sort, !3 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   NEW                                                  $4      'Demo'
          1        SEND_VAL_EX                                                  'ghi'
          2        DO_FCALL                                          0          
          3        INIT_ARRAY                                           ~6      $4, 'data'
          4        INIT_ARRAY                                           ~7      ~6
   20     5        NEW                                                  $8      'Demo'
          6        SEND_VAL_EX                                                  'def'
          7        DO_FCALL                                          0          
          8        INIT_ARRAY                                           ~10     $8, 'data'
          9        ADD_ARRAY_ELEMENT                                    ~7      ~10
   21    10        NEW                                                  $11     'Demo'
         11        SEND_VAL_EX                                                  'jkl'
         12        DO_FCALL                                          0          
         13        INIT_ARRAY                                           ~13     $11, 'data'
         14        ADD_ARRAY_ELEMENT                                    ~7      ~13
   22    15        NEW                                                  $14     'Demo'
         16        SEND_VAL_EX                                                  'abc'
         17        DO_FCALL                                          0          
         18        INIT_ARRAY                                           ~16     $14, 'data'
         19        ADD_ARRAY_ELEMENT                                    ~7      ~16
         20        INIT_ARRAY                                           ~17     ~7, 'cart_contents'
         21        CAST                                              8  ~18     ~17
   17    22        ASSIGN                                                       !0, ~18
   26    23        ASSIGN                                                       !1, <array>
   27    24        ASSIGN                                                       !2, <array>
   29    25        FETCH_OBJ_R                                          ~22     !0, 'cart_contents'
         26      > FE_RESET_R                                           $23     ~22, ->34
         27    > > FE_FETCH_R                                                   $23, !3, ->34
   30    28    >   FETCH_DIM_R                                          ~25     !3, 'data'
         29        INIT_METHOD_CALL                                             ~25, 'get_sku'
         30        DO_FCALL                                          0  $26     
         31        ASSIGN_DIM                                                   !1
         32        OP_DATA                                                      $26
   29    33      > JMP                                                          ->27
         34    >   FE_FREE                                                      $23
   32    35        INIT_FCALL                                                   'array_multisort'
         36        SEND_REF                                                     !1
         37        FETCH_OBJ_W                                          $27     !0, 'cart_contents'
         38        SEND_REF                                                     $27
         39        DO_ICALL                                                     
   33    40        INIT_FCALL                                                   'var_export'
         41        FETCH_OBJ_R                                          ~29     !0, 'cart_contents'
         42        SEND_VAL                                                     ~29
         43        DO_ICALL                                                     
         44      > RETURN                                                       1

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

End of function __construct

Function get_sku:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YE75c
function name:  get_sku
number of ops:  4
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   FETCH_OBJ_R                                          ~0      'val'
          1        FETCH_DIM_R                                          ~1      <array>, ~0
          2      > RETURN                                                       ~1
   14     3*     > RETURN                                                       null

End of function get_sku

End of class Demo.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
155.75 ms | 1639 KiB | 15 Q