3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Collection { private $things; public function construct(Thing ...$things) { var_dump($things); $this->things = $things; } public function applyToAll() { /** * This was the function in question */ array_map(function($thing) { $thing->apply(); }, $this->things); } } interface Thing { public function apply(); } class FooThing implements Thing { public function apply() { echo 'applied the way Foo does things.'; } } class BarThing implements Thing { public function apply() { echo 'Bar had something different done to it.'; } } $collection = new Collection(new FooThing, new BarThing); $collection->applyToAll();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M6j9s
function name:  (null)
number of ops:  14
compiled vars:  !0 = $collection
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   DECLARE_CLASS                                            'foothing'
   37     1        DECLARE_CLASS                                            'barthing'
   45     2        NEW                                              $1      'Collection'
          3        NEW                                              $2      'FooThing'
          4        DO_FCALL                                      0          
          5        SEND_VAR_NO_REF_EX                                       $2
          6        NEW                                              $4      'BarThing'
          7        DO_FCALL                                      0          
          8        SEND_VAR_NO_REF_EX                                       $4
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !0, $1
   46    11        INIT_METHOD_CALL                                         !0, 'applyToAll'
         12        DO_FCALL                                      0          
         13      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FM6j9s%3A18%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M6j9s
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $thing
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        INIT_METHOD_CALL                                         !0, 'apply'
          2        DO_FCALL                                      0          
   20     3      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FM6j9s%3A18%240

Class Collection:
Function construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M6j9s
function name:  construct
number of ops:  7
compiled vars:  !0 = $things
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV_VARIADIC                                    !0      
    9     1        INIT_FCALL                                               'var_dump'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                                 
   10     4        ASSIGN_OBJ                                               'things'
          5        OP_DATA                                                  !0
   11     6      > RETURN                                                   null

End of function construct

Function applytoall:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M6j9s
function name:  applyToAll
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   INIT_FCALL                                               'array_map'
          1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FM6j9s%3A18%240'
   20     2        SEND_VAL                                                 ~0
          3        FETCH_OBJ_R                                      ~1      'things'
          4        SEND_VAL                                                 ~1
          5        DO_ICALL                                                 
   21     6      > RETURN                                                   null

End of function applytoall

End of class Collection.

Class Thing:
Function apply:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M6j9s
function name:  apply
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E > > RETURN                                                   null

End of function apply

End of class Thing.

Class FooThing:
Function apply:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M6j9s
function name:  apply
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   ECHO                                                     'applied+the+way+Foo+does+things.'
   34     1      > RETURN                                                   null

End of function apply

End of class FooThing.

Class BarThing:
Function apply:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M6j9s
function name:  apply
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   ECHO                                                     'Bar+had+something+different+done+to+it.'
   42     1      > RETURN                                                   null

End of function apply

End of class BarThing.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.94 ms | 1405 KiB | 17 Q