3v4l.org

run code in 300+ PHP versions simultaneously
<?php class EventBus { public function addEventListener(Listener $listener) { $this->listeners[] = $listener; } public function dispatch(Event ...$events) { foreach($events as $event){ foreach($this->listeners as $listener){ $listener->when($event); } } } } abstract class Listener { public function __construct(EventBus $bus) { $bus->addEventListener($this); } public function when(Event $event) { $method = explode('\\', get_class($event)); $method = 'on' . end($method); if (method_exists($this, $method)) { $this->$method($event); } } } class SendEmailListener extends Listener { public function onMemberRegistered(Event $event) { // send email } } $eventBus = new EventBus; new SendEmailListener($eventBus);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LTG2d
function name:  (null)
number of ops:  8
compiled vars:  !0 = $eventBus
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   NEW                                              $1      'EventBus'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   46     3        NEW                                              $4      'SendEmailListener'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6        FREE                                                     $4
          7      > RETURN                                                   1

Class EventBus:
Function addeventlistener:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LTG2d
function name:  addEventListener
number of ops:  5
compiled vars:  !0 = $listener
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    7     1        FETCH_OBJ_W                                      $1      'listeners'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
    8     4      > RETURN                                                   null

End of function addeventlistener

Function dispatch:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 12
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 10
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/LTG2d
function name:  dispatch
number of ops:  14
compiled vars:  !0 = $events, !1 = $event, !2 = $listener
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV_VARIADIC                                    !0      
   12     1      > FE_RESET_R                                       $3      !0, ->12
          2    > > FE_FETCH_R                                               $3, !1, ->12
   13     3    >   FETCH_OBJ_R                                      ~4      'listeners'
          4      > FE_RESET_R                                       $5      ~4, ->10
          5    > > FE_FETCH_R                                               $5, !2, ->10
   14     6    >   INIT_METHOD_CALL                                         !2, 'when'
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0          
   13     9      > JMP                                                      ->5
         10    >   FE_FREE                                                  $5
   12    11      > JMP                                                      ->2
         12    >   FE_FREE                                                  $3
   17    13      > RETURN                                                   null

End of function dispatch

End of class EventBus.

Class Listener:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LTG2d
function name:  __construct
number of ops:  6
compiled vars:  !0 = $bus
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   24     1        INIT_METHOD_CALL                                         !0, 'addEventListener'
          2        FETCH_THIS                                       $1      
          3        SEND_VAR_EX                                              $1
          4        DO_FCALL                                      0          
   25     5      > RETURN                                                   null

End of function __construct

Function when:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/LTG2d
function name:  when
number of ops:  22
compiled vars:  !0 = $event, !1 = $method
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   29     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%5C'
          3        GET_CLASS                                        ~2      !0
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !1, $3
   30     7        INIT_FCALL                                               'end'
          8        SEND_REF                                                 !1
          9        DO_ICALL                                         $5      
         10        CONCAT                                           ~6      'on', $5
         11        ASSIGN                                                   !1, ~6
   31    12        INIT_FCALL                                               'method_exists'
         13        FETCH_THIS                                       ~8      
         14        SEND_VAL                                                 ~8
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $9      
         17      > JMPZ                                                     $9, ->21
   32    18    >   INIT_METHOD_CALL                                         !1
         19        SEND_VAR_EX                                              !0
         20        DO_FCALL                                      0          
   34    21    > > RETURN                                                   null

End of function when

End of class Listener.

Class SendEmailListener:
Function onmemberregistered:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LTG2d
function name:  onMemberRegistered
number of ops:  2
compiled vars:  !0 = $event
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   42     1      > RETURN                                                   null

End of function onmemberregistered

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LTG2d
function name:  __construct
number of ops:  6
compiled vars:  !0 = $bus
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   24     1        INIT_METHOD_CALL                                         !0, 'addEventListener'
          2        FETCH_THIS                                       $1      
          3        SEND_VAR_EX                                              $1
          4        DO_FCALL                                      0          
   25     5      > RETURN                                                   null

End of function __construct

Function when:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/LTG2d
function name:  when
number of ops:  22
compiled vars:  !0 = $event, !1 = $method
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   29     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%5C'
          3        GET_CLASS                                        ~2      !0
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !1, $3
   30     7        INIT_FCALL                                               'end'
          8        SEND_REF                                                 !1
          9        DO_ICALL                                         $5      
         10        CONCAT                                           ~6      'on', $5
         11        ASSIGN                                                   !1, ~6
   31    12        INIT_FCALL                                               'method_exists'
         13        FETCH_THIS                                       ~8      
         14        SEND_VAL                                                 ~8
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $9      
         17      > JMPZ                                                     $9, ->21
   32    18    >   INIT_METHOD_CALL                                         !1
         19        SEND_VAR_EX                                              !0
         20        DO_FCALL                                      0          
   34    21    > > RETURN                                                   null

End of function when

End of class SendEmailListener.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.11 ms | 1404 KiB | 19 Q