3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Event { private $eventName; function __construct($eventName){ $this->eventName = $eventName; } public function name() { return $this->eventName; } } class QueueManager { private $registeredHandlers = array(); public function addEventListener($eventName, $handler) { if (!isset($this->registeredHandlers[$eventName]) || !is_array($this->registeredHandlers[$eventName])) $this->registeredHandlers[$eventName] = array(); $this->registeredHandlers[$eventName][] = $handler; } public function dispatch($event, &...$args) { $eventName = $event->name(); if (!$this->registeredHandlers[$eventName]) return; foreach ($this->registeredHandlers[$eventName] as $handler) call_user_func_array($handler, $args); } } $qm = new QueueManager(); $qm->addEventListener('click', function(){echo 'ok1';}); //something like this working $qm->addEventListener('click', function(){echo 'ok2';}); $qm->addEventListener('adding', function(&$x){$x = 5;}); //something like this not working $qm->addEventListener('adding', function(&$x){$x++;}); $qm->addEventListener('adding', function($x){echo $x;}); $clickEvent = new Event('click'); $qm->dispatch($clickEvent); $addingEvent = new Event('adding'); $value; $qm->dispatch($addingEvent, $value);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ud0NT
function name:  (null)
number of ops:  44
compiled vars:  !0 = $qm, !1 = $clickEvent, !2 = $addingEvent, !3 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   NEW                                              $4      'QueueManager'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
   26     3        INIT_METHOD_CALL                                         !0, 'addEventListener'
          4        SEND_VAL_EX                                              'click'
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FUd0NT%3A26%240'
          6        SEND_VAL_EX                                              ~7
          7        DO_FCALL                                      0          
   27     8        INIT_METHOD_CALL                                         !0, 'addEventListener'
          9        SEND_VAL_EX                                              'click'
         10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FUd0NT%3A27%241'
         11        SEND_VAL_EX                                              ~9
         12        DO_FCALL                                      0          
   28    13        INIT_METHOD_CALL                                         !0, 'addEventListener'
         14        SEND_VAL_EX                                              'adding'
         15        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FUd0NT%3A28%242'
         16        SEND_VAL_EX                                              ~11
         17        DO_FCALL                                      0          
   29    18        INIT_METHOD_CALL                                         !0, 'addEventListener'
         19        SEND_VAL_EX                                              'adding'
         20        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FUd0NT%3A29%243'
         21        SEND_VAL_EX                                              ~13
         22        DO_FCALL                                      0          
   30    23        INIT_METHOD_CALL                                         !0, 'addEventListener'
         24        SEND_VAL_EX                                              'adding'
         25        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FUd0NT%3A30%244'
         26        SEND_VAL_EX                                              ~15
         27        DO_FCALL                                      0          
   32    28        NEW                                              $17     'Event'
         29        SEND_VAL_EX                                              'click'
         30        DO_FCALL                                      0          
         31        ASSIGN                                                   !1, $17
   33    32        INIT_METHOD_CALL                                         !0, 'dispatch'
         33        SEND_VAR_EX                                              !1
         34        DO_FCALL                                      0          
   35    35        NEW                                              $21     'Event'
         36        SEND_VAL_EX                                              'adding'
         37        DO_FCALL                                      0          
         38        ASSIGN                                                   !2, $21
   37    39        INIT_METHOD_CALL                                         !0, 'dispatch'
         40        SEND_VAR_EX                                              !2
         41        SEND_VAR_EX                                              !3
         42        DO_FCALL                                      0          
         43      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FUd0NT%3A26%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ud0NT
function name:  {closure}
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ECHO                                                     'ok1'
          1      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FUd0NT%3A26%240

Function %00%7Bclosure%7D%2Fin%2FUd0NT%3A27%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ud0NT
function name:  {closure}
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   ECHO                                                     'ok2'
          1      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FUd0NT%3A27%241

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

End of function %00%7Bclosure%7D%2Fin%2FUd0NT%3A28%242

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

End of function %00%7Bclosure%7D%2Fin%2FUd0NT%3A29%243

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

End of function %00%7Bclosure%7D%2Fin%2FUd0NT%3A30%244

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

End of function __construct

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

End of function name

End of class Event.

Class QueueManager:
Function addeventlistener:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
Branch analysis from position: 11
filename:       /in/Ud0NT
function name:  addEventListener
number of ops:  20
compiled vars:  !0 = $eventName, !1 = $handler
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2        FETCH_OBJ_IS                                     ~2      'registeredHandlers'
          3        ISSET_ISEMPTY_DIM_OBJ                         0  ~3      ~2, !0
          4        BOOL_NOT                                         ~4      ~3
          5      > JMPNZ_EX                                         ~4      ~4, ->11
          6    >   FETCH_OBJ_R                                      ~5      'registeredHandlers'
          7        FETCH_DIM_R                                      ~6      ~5, !0
          8        TYPE_CHECK                                  128  ~7      ~6
          9        BOOL_NOT                                         ~8      ~7
         10        BOOL                                             ~4      ~8
         11    > > JMPZ                                                     ~4, ->15
         12    >   FETCH_OBJ_W                                      $9      'registeredHandlers'
         13        ASSIGN_DIM                                               $9, !0
         14        OP_DATA                                                  <array>
   16    15    >   FETCH_OBJ_W                                      $11     'registeredHandlers'
         16        FETCH_DIM_W                                      $12     $11, !0
         17        ASSIGN_DIM                                               $12
         18        OP_DATA                                                  !1
   17    19      > RETURN                                                   null

End of function addeventlistener

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

End of function dispatch

End of class QueueManager.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.59 ms | 1407 KiB | 13 Q