3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $groupId; private $value; function __construct($groupId, $value) { $this->groupId = $groupId; $this->value = $value; } function getGroupId() { return $this->groupId; } }; $foos = [ new Foo(1, 'Bar'), new Foo(1, 'Ban'), new Foo(1, 'Bak'), new Foo(2, 'Gas'), new Foo(2, 'Gar'), ]; var_dump(array_reduce($foos, function($carry, $item){ if(!isset($carry[$item->getGroupId()])) { $carry[$item->getGroupId()] = []; } $carry[$item->getGroupId()][] = $item; return $carry; }, []));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qWO1f
function name:  (null)
number of ops:  36
compiled vars:  !0 = $foos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   NEW                                              $1      'Foo'
          1        SEND_VAL_EX                                              1
          2        SEND_VAL_EX                                              'Bar'
          3        DO_FCALL                                      0          
          4        INIT_ARRAY                                       ~3      $1
   19     5        NEW                                              $4      'Foo'
          6        SEND_VAL_EX                                              1
          7        SEND_VAL_EX                                              'Ban'
          8        DO_FCALL                                      0          
          9        ADD_ARRAY_ELEMENT                                ~3      $4
   20    10        NEW                                              $6      'Foo'
         11        SEND_VAL_EX                                              1
         12        SEND_VAL_EX                                              'Bak'
         13        DO_FCALL                                      0          
         14        ADD_ARRAY_ELEMENT                                ~3      $6
   21    15        NEW                                              $8      'Foo'
         16        SEND_VAL_EX                                              2
         17        SEND_VAL_EX                                              'Gas'
         18        DO_FCALL                                      0          
         19        ADD_ARRAY_ELEMENT                                ~3      $8
   22    20        NEW                                              $10     'Foo'
         21        SEND_VAL_EX                                              2
         22        SEND_VAL_EX                                              'Gar'
         23        DO_FCALL                                      0          
         24        ADD_ARRAY_ELEMENT                                ~3      $10
   17    25        ASSIGN                                                   !0, ~3
   25    26        INIT_FCALL                                               'var_dump'
         27        INIT_FCALL                                               'array_reduce'
         28        SEND_VAR                                                 !0
         29        DECLARE_LAMBDA_FUNCTION                          ~13     [0]
   32    30        SEND_VAL                                                 ~13
         31        SEND_VAL                                                 <array>
   25    32        DO_ICALL                                         $14     
   32    33        SEND_VAR                                                 $14
   25    34        DO_ICALL                                                 
   32    35      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/qWO1f
function name:  {closure}
number of ops:  18
compiled vars:  !0 = $carry, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   26     2        INIT_METHOD_CALL                                         !1, 'getGroupId'
          3        DO_FCALL                                      0  $2      
          4        ISSET_ISEMPTY_DIM_OBJ                         0  ~3      !0, $2
          5        BOOL_NOT                                         ~4      ~3
          6      > JMPZ                                                     ~4, ->11
   27     7    >   INIT_METHOD_CALL                                         !1, 'getGroupId'
          8        DO_FCALL                                      0  $5      
          9        ASSIGN_DIM                                               !0, $5
         10        OP_DATA                                                  <array>
   30    11    >   INIT_METHOD_CALL                                         !1, 'getGroupId'
         12        DO_FCALL                                      0  $7      
         13        FETCH_DIM_W                                      $8      !0, $7
         14        ASSIGN_DIM                                               $8
         15        OP_DATA                                                  !1
   31    16      > RETURN                                                   !0
   32    17*     > RETURN                                                   null

End of Dynamic Function 0

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

End of function __construct

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

End of function getgroupid

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.06 ms | 1006 KiB | 15 Q