3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Observer { static protected $events = array(); static public function register($callable, $event){ if (!isset(self::$events[$event])) { self::$events[$event] = array(); } self::$events[$event][] = $callable; } static public function notify($event, $params = array()) { if (isset(self::$events[$event])) { foreach (self::$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::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'); echo "Notifying of event 1 \r\n"; Observer::notify('event1', array(1, 2)); echo "Notifying of event 2 \r\n"; Observer::notify('event2', array(3, 4)); echo "Notifying of event 3 \r\n"; Observer::notify('event3', array(5, 6));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lQbgs
function name:  (null)
number of ops:  40
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   INIT_STATIC_METHOD_CALL                                  'Observer', 'register'
          1        SEND_VAL                                                 'print_meta'
          2        SEND_VAL                                                 'event1'
          3        DO_FCALL                                      0          
   33     4        INIT_STATIC_METHOD_CALL                                  'Observer', 'register'
          5        SEND_VAL                                                 'multiply_meta'
          6        SEND_VAL                                                 'event1'
          7        DO_FCALL                                      0          
   35     8        INIT_STATIC_METHOD_CALL                                  'Observer', 'register'
          9        SEND_VAL                                                 'print_meta'
         10        SEND_VAL                                                 'event2'
         11        DO_FCALL                                      0          
   36    12        INIT_STATIC_METHOD_CALL                                  'Observer', 'register'
         13        SEND_VAL                                                 'add_meta'
         14        SEND_VAL                                                 'event2'
         15        DO_FCALL                                      0          
   38    16        INIT_STATIC_METHOD_CALL                                  'Observer', 'register'
         17        SEND_VAL                                                 'multiply_meta'
         18        SEND_VAL                                                 'event3'
         19        DO_FCALL                                      0          
   39    20        INIT_STATIC_METHOD_CALL                                  'Observer', 'register'
         21        SEND_VAL                                                 'add_meta'
         22        SEND_VAL                                                 'event3'
         23        DO_FCALL                                      0          
   41    24        ECHO                                                     'Notifying+of+event+1+%0D%0A'
   42    25        INIT_STATIC_METHOD_CALL                                  'Observer', 'notify'
         26        SEND_VAL                                                 'event1'
         27        SEND_VAL                                                 <array>
         28        DO_FCALL                                      0          
   43    29        ECHO                                                     'Notifying+of+event+2+%0D%0A'
   44    30        INIT_STATIC_METHOD_CALL                                  'Observer', 'notify'
         31        SEND_VAL                                                 'event2'
         32        SEND_VAL                                                 <array>
         33        DO_FCALL                                      0          
   45    34        ECHO                                                     'Notifying+of+event+3+%0D%0A'
   46    35        INIT_STATIC_METHOD_CALL                                  'Observer', 'notify'
         36        SEND_VAL                                                 'event3'
         37        SEND_VAL                                                 <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/lQbgs
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/lQbgs
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/lQbgs
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 Observer:
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/lQbgs
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_STATIC_PROP_IS                             ~2      'events'
          3        ISSET_ISEMPTY_DIM_OBJ                         0  ~3      ~2, !1
          4        BOOL_NOT                                         ~4      ~3
          5      > JMPZ                                                     ~4, ->9
    7     6    >   FETCH_STATIC_PROP_W          unknown             $5      'events'
          7        ASSIGN_DIM                                               $5, !1
          8        OP_DATA                                                  <array>
    9     9    >   FETCH_STATIC_PROP_W          unknown             $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/lQbgs
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_STATIC_PROP_IS                             ~3      'events'
          3        ISSET_ISEMPTY_DIM_OBJ                         0          ~3, !0
          4      > JMPZ                                                     ~4, ->15
   13     5    >   FETCH_STATIC_PROP_R          unknown             ~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 Observer.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
191.6 ms | 1403 KiB | 13 Q