3v4l.org

run code in 300+ PHP versions simultaneously
<?php function event($name,$cb = null){ static $e = array(); if ( is_callable($cb) ){ empty( $e[$name] ) ? $e[$name] = array($cb) : $e[$name][] = $cb; } elseif ( false === empty($e[$name]) ) { $a = is_array($cb) ? $cb : array(); foreach ($e[$name] as $eh) call_user_func_array($eh,$a); } } // Add a foo event handler event('foo',function(){ print_r(func_get_args()); }); // Add another foo event handler event('foo',function(){ echo 'Hello, friend!'; }); // Call foo event with parameters event('foo',[1,2]); // Call bar event (does nothing) event('bar');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Jo162
function name:  (null)
number of ops:  18
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'event'
          1        SEND_VAL                                                 'foo'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FJo162%3A13%240'
   15     3        SEND_VAL                                                 ~0
          4        DO_FCALL                                      0          
   18     5        INIT_FCALL                                               'event'
          6        SEND_VAL                                                 'foo'
          7        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FJo162%3A18%241'
   20     8        SEND_VAL                                                 ~2
          9        DO_FCALL                                      0          
   24    10        INIT_FCALL                                               'event'
         11        SEND_VAL                                                 'foo'
         12        SEND_VAL                                                 <array>
         13        DO_FCALL                                      0          
   27    14        INIT_FCALL                                               'event'
         15        SEND_VAL                                                 'bar'
         16        DO_FCALL                                      0          
         17      > RETURN                                                   1

Function event:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 20
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 38
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 77) Position 1 = 31, Position 2 = 37
Branch analysis from position: 31
2 jumps found. (Code = 78) Position 1 = 32, Position 2 = 37
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
Branch analysis from position: 27
2 jumps found. (Code = 77) Position 1 = 31, Position 2 = 37
Branch analysis from position: 31
Branch analysis from position: 37
Branch analysis from position: 38
filename:       /in/Jo162
function name:  event
number of ops:  39
compiled vars:  !0 = $name, !1 = $cb, !2 = $e, !3 = $a, !4 = $eh
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
    3     2        BIND_STATIC                                              !2
    4     3        INIT_FCALL                                               'is_callable'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $5      
          6      > JMPZ                                                     $5, ->20
    5     7    >   ISSET_ISEMPTY_DIM_OBJ                         1          !2, !0
          8      > JMPZ                                                     ~6, ->14
          9    >   INIT_ARRAY                                       ~8      !1
         10        ASSIGN_DIM                                       ~7      !2, !0
         11        OP_DATA                                                  ~8
         12        QM_ASSIGN                                        ~9      ~7
         13      > JMP                                                      ->18
         14    >   FETCH_DIM_W                                      $10     !2, !0
         15        ASSIGN_DIM                                       ~11     $10
         16        OP_DATA                                                  !1
         17        QM_ASSIGN                                        ~9      ~11
         18    >   FREE                                                     ~9
         19      > JMP                                                      ->38
    6    20    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~12     !2, !0
         21        TYPE_CHECK                                    4          ~12
         22      > JMPZ                                                     ~13, ->38
    7    23    >   TYPE_CHECK                                  128          !1
         24      > JMPZ                                                     ~14, ->27
         25    >   QM_ASSIGN                                        ~15     !1
         26      > JMP                                                      ->28
         27    >   QM_ASSIGN                                        ~15     <array>
         28    >   ASSIGN                                                   !3, ~15
    8    29        FETCH_DIM_R                                      ~17     !2, !0
         30      > FE_RESET_R                                       $18     ~17, ->37
         31    > > FE_FETCH_R                                               $18, !4, ->37
         32    >   INIT_USER_CALL                                0          'call_user_func_array', !4
         33        SEND_ARRAY                                               !3
         34        CHECK_UNDEF_ARGS                                         
         35        DO_FCALL                                      0          
         36      > JMP                                                      ->31
         37    >   FE_FREE                                                  $18
   10    38    > > RETURN                                                   null

End of function event

Function %00%7Bclosure%7D%2Fin%2FJo162%3A13%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Jo162
function name:  {closure}
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   INIT_FCALL                                               'print_r'
          1        FUNC_GET_ARGS                                    ~0      
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                                 
   15     4      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FJo162%3A13%240

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

End of function %00%7Bclosure%7D%2Fin%2FJo162%3A18%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.81 ms | 1407 KiB | 21 Q