3v4l.org

run code in 300+ PHP versions simultaneously
<?php class BaseObserver { protected $events = array(); public function register($callable, $event){ if (!isset($this->events[$event])) { $this->events[$event] = array(); } $this->events[$event][] = $callable; } public function notify($event, $params = array()) { if (isset($this->events[$event])) { foreach ($this->events[$event] AS $callable){ call_user_func_array($callable, $params); } } } } function print_meta($p1, $p2) { echo $p1 . ' ' . $p2; } function multiply_meta($p1, $p2) { echo $p1 * $p2; } function add_meta($p1, $p2) { echo $p1 + $p2; } $observer = new BaseObserver(); $observer->register('print_meta', 'event1'); $observer->register('multiply_meta', 'event1'); $observer->register('print_meta', 'event2'); $observer->register('add_meta', 'event2'); $observer->register('multiply_meta', 'event3'); $observer->register('add_meta', 'event3'); $observer->notify('event1', array(1, 2)); $observer->notify('event2', array(3, 4)); $observer->notify('event3', array(5, 6));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sMGjG
function name:  (null)
number of ops:  40
compiled vars:  !0 = $observer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   NEW                                              $1      'BaseObserver'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   33     3        INIT_METHOD_CALL                                         !0, 'register'
          4        SEND_VAL_EX                                              'print_meta'
          5        SEND_VAL_EX                                              'event1'
          6        DO_FCALL                                      0          
   34     7        INIT_METHOD_CALL                                         !0, 'register'
          8        SEND_VAL_EX                                              'multiply_meta'
          9        SEND_VAL_EX                                              'event1'
         10        DO_FCALL                                      0          
   35    11        INIT_METHOD_CALL                                         !0, 'register'
         12        SEND_VAL_EX                                              'print_meta'
         13        SEND_VAL_EX                                              'event2'
         14        DO_FCALL                                      0          
   36    15        INIT_METHOD_CALL                                         !0, 'register'
         16        SEND_VAL_EX                                              'add_meta'
         17        SEND_VAL_EX                                              'event2'
         18        DO_FCALL                                      0          
   37    19        INIT_METHOD_CALL                                         !0, 'register'
         20        SEND_VAL_EX                                              'multiply_meta'
         21        SEND_VAL_EX                                              'event3'
         22        DO_FCALL                                      0          
   38    23        INIT_METHOD_CALL                                         !0, 'register'
         24        SEND_VAL_EX                                              'add_meta'
         25        SEND_VAL_EX                                              'event3'
         26        DO_FCALL                                      0          
   40    27        INIT_METHOD_CALL                                         !0, 'notify'
         28        SEND_VAL_EX                                              'event1'
         29        SEND_VAL_EX                                              <array>
         30        DO_FCALL                                      0          
   41    31        INIT_METHOD_CALL                                         !0, 'notify'
         32        SEND_VAL_EX                                              'event2'
         33        SEND_VAL_EX                                              <array>
         34        DO_FCALL                                      0          
   42    35        INIT_METHOD_CALL                                         !0, 'notify'
         36        SEND_VAL_EX                                              'event3'
         37        SEND_VAL_EX                                              <array>
         38        DO_FCALL                                      0          
         39      > RETURN                                                   1

Function print_meta:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sMGjG
function name:  print_meta
number of ops:  6
compiled vars:  !0 = $p1, !1 = $p2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   21     2        CONCAT                                           ~2      !0, '+'
          3        CONCAT                                           ~3      ~2, !1
          4        ECHO                                                     ~3
   22     5      > RETURN                                                   null

End of function print_meta

Function multiply_meta:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sMGjG
function name:  multiply_meta
number of ops:  5
compiled vars:  !0 = $p1, !1 = $p2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   25     2        MUL                                              ~2      !0, !1
          3        ECHO                                                     ~2
   26     4      > RETURN                                                   null

End of function multiply_meta

Function add_meta:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sMGjG
function name:  add_meta
number of ops:  5
compiled vars:  !0 = $p1, !1 = $p2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   29     2        ADD                                              ~2      !0, !1
          3        ECHO                                                     ~2
   30     4      > RETURN                                                   null

End of function add_meta

Class BaseObserver:
Function register:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/sMGjG
function name:  register
number of ops:  14
compiled vars:  !0 = $callable, !1 = $event
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        FETCH_OBJ_IS                                     ~2      'events'
          3        ISSET_ISEMPTY_DIM_OBJ                         0  ~3      ~2, !1
          4        BOOL_NOT                                         ~4      ~3
          5      > JMPZ                                                     ~4, ->9
    7     6    >   FETCH_OBJ_W                                      $5      'events'
          7        ASSIGN_DIM                                               $5, !1
          8        OP_DATA                                                  <array>
    9     9    >   FETCH_OBJ_W                                      $7      'events'
         10        FETCH_DIM_W                                      $8      $7, !1
         11        ASSIGN_DIM                                               $8
         12        OP_DATA                                                  !0
   10    13      > RETURN                                                   null

End of function register

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

End of function notify

End of class BaseObserver.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.92 ms | 1403 KiB | 13 Q