3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Events { private $events; public function add($event, callable $callback) { $this->events[$event][] = $callback; } public function run($event, array $args = []) { if (!isset($this->events[$event])) { return; } foreach ($this->events[$event] as $e) { call_user_func_array($e, $args); } } } $testVar = 1; $events = new Events; $events->add('test', function(&$var) { $var = 2; }); $events->run('test', [&$testVar]); echo $testVar;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GVlsG
function name:  (null)
number of ops:  16
compiled vars:  !0 = $testVar, !1 = $events
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   ASSIGN                                                   !0, 1
   26     1        NEW                                              $3      'Events'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $3
   28     4        INIT_METHOD_CALL                                         !1, 'add'
          5        SEND_VAL_EX                                              'test'
          6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FGVlsG%3A28%240'
   30     7        SEND_VAL_EX                                              ~6
          8        DO_FCALL                                      0          
   32     9        INIT_METHOD_CALL                                         !1, 'run'
         10        SEND_VAL_EX                                              'test'
         11        INIT_ARRAY                                       ~8      !0
         12        SEND_VAL_EX                                              ~8
         13        DO_FCALL                                      0          
   34    14        ECHO                                                     !0
         15      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FGVlsG%3A28%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GVlsG
function name:  {closure}
number of ops:  3
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   29     1        ASSIGN                                                   !0, 2
   30     2      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FGVlsG%3A28%240

Class Events:
Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GVlsG
function name:  add
number of ops:  7
compiled vars:  !0 = $event, !1 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        FETCH_OBJ_W                                      $2      'events'
          3        FETCH_DIM_W                                      $3      $2, !0
          4        ASSIGN_DIM                                               $3
          5        OP_DATA                                                  !1
    9     6      > RETURN                                                   null

End of function add

Function run:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/GVlsG
function name:  run
number of ops:  18
compiled vars:  !0 = $event, !1 = $args, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   13     2        FETCH_OBJ_IS                                     ~3      'events'
          3        ISSET_ISEMPTY_DIM_OBJ                         0  ~4      ~3, !0
          4        BOOL_NOT                                         ~5      ~4
          5      > JMPZ                                                     ~5, ->7
   14     6    > > RETURN                                                   null
   17     7    >   FETCH_OBJ_R                                      ~6      'events'
          8        FETCH_DIM_R                                      ~7      ~6, !0
          9      > FE_RESET_R                                       $8      ~7, ->16
         10    > > FE_FETCH_R                                               $8, !2, ->16
   18    11    >   INIT_USER_CALL                                0          'call_user_func_array', !2
         12        SEND_ARRAY                                               !1
         13        CHECK_UNDEF_ARGS                                         
         14        DO_FCALL                                      0          
   17    15      > JMP                                                      ->10
         16    >   FE_FREE                                                  $8
   20    17      > RETURN                                                   null

End of function run

End of class Events.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.06 ms | 1399 KiB | 13 Q