3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Collection { private $things; public function __construct(Thing ...$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/pjbaa
function name:  (null)
number of ops:  14
compiled vars:  !0 = $collection
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   DECLARE_CLASS                                            'foothing'
   36     1        DECLARE_CLASS                                            'barthing'
   44     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
   45    11        INIT_METHOD_CALL                                         !0, 'applyToAll'
         12        DO_FCALL                                      0          
         13      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2Fpjbaa%3A17%240

Class Collection:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pjbaa
function name:  __construct
number of ops:  4
compiled vars:  !0 = $things
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV_VARIADIC                                    !0      
    9     1        ASSIGN_OBJ                                               'things'
          2        OP_DATA                                                  !0
   10     3      > 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/pjbaa
function name:  applyToAll
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   INIT_FCALL                                               'array_map'
          1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fpjbaa%3A17%240'
   19     2        SEND_VAL                                                 ~0
          3        FETCH_OBJ_R                                      ~1      'things'
          4        SEND_VAL                                                 ~1
          5        DO_ICALL                                                 
   20     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/pjbaa
function name:  apply
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     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/pjbaa
function name:  apply
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   ECHO                                                     'applied+the+way+Foo+does+things.'
   33     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/pjbaa
function name:  apply
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   ECHO                                                     'Bar+had+something+different+done+to+it.'
   41     1      > RETURN                                                   null

End of function apply

End of class BarThing.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.24 ms | 1400 KiB | 15 Q