3v4l.org

run code in 300+ PHP versions simultaneously
<?php function e($n,$p,$c=0){static $a;@krsort($a[$n]);if($c)$a[$n][$p][]=$c;else foreach($a[$n] as$q)foreach($q as$r)$r($p);} function it($m,$p){echo ($p?'✔︎':'✘')." It $m\n"; if(!$p){$GLOBALS['f']=1;}}function done(){if(@$GLOBALS['f'])die(1);} ob_start(); e( 'event', 0, function ($data) { echo "event, $data, priority 0;"; } ); e( 'event', 10, function ($data) { echo "event, $data, priority 10;"; } ); e( 'other_event', -5, function ($data) { echo "other_event, $data, priority -5;"; } ); e( 'other_event', 5, function ($data) { echo "other_event, $data priority 5;"; } ); e('event', 'dataX'); e('other_event', 'dataY'); $output = ob_get_contents(); ob_end_clean(); it( 'calls event listeners in the right order', $output === 'event, dataX, priority 10;event, dataX, priority 0;other_event, dataY priority 5;other_event, dataY, priority -5;' ); class Foo { private $eventDispatcher; function __construct($eventDispatcher) { var_dump($eventDispatcher); $this->eventDispatcher = $eventDispatcher; } function doStuff() { // ... call_user_func($this->eventDispatcher, "my_event", "my data"); } } ob_start(); $foo = new Foo(@e); e("my_event", 5, function($data) { echo "My event was called with '$data'";}); $foo->doStuff(); $output = ob_get_contents();ob_end_clean(); it( 'is perfectly possible to inject the event dispatcher as a dependency into classes.', $output === "My event was called with 'my data'" );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eJhvp
function name:  (null)
number of ops:  72
compiled vars:  !0 = $output, !1 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   INIT_FCALL                                               'ob_start'
          1        DO_ICALL                                                 
    6     2        INIT_FCALL                                               'e'
    7     3        SEND_VAL                                                 'event'
    8     4        SEND_VAL                                                 0
    9     5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FeJhvp%3A9%240'
   11     6        SEND_VAL                                                 ~3
          7        DO_FCALL                                      0          
   13     8        INIT_FCALL                                               'e'
   14     9        SEND_VAL                                                 'event'
   15    10        SEND_VAL                                                 10
   16    11        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FeJhvp%3A16%241'
   18    12        SEND_VAL                                                 ~5
         13        DO_FCALL                                      0          
   20    14        INIT_FCALL                                               'e'
   21    15        SEND_VAL                                                 'other_event'
   22    16        SEND_VAL                                                 -5
   23    17        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FeJhvp%3A23%242'
   25    18        SEND_VAL                                                 ~7
         19        DO_FCALL                                      0          
   27    20        INIT_FCALL                                               'e'
   28    21        SEND_VAL                                                 'other_event'
   29    22        SEND_VAL                                                 5
   30    23        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FeJhvp%3A30%243'
   32    24        SEND_VAL                                                 ~9
         25        DO_FCALL                                      0          
   34    26        INIT_FCALL                                               'e'
         27        SEND_VAL                                                 'event'
         28        SEND_VAL                                                 'dataX'
         29        DO_FCALL                                      0          
   35    30        INIT_FCALL                                               'e'
         31        SEND_VAL                                                 'other_event'
         32        SEND_VAL                                                 'dataY'
         33        DO_FCALL                                      0          
   36    34        INIT_FCALL                                               'ob_get_contents'
         35        DO_ICALL                                         $13     
         36        ASSIGN                                                   !0, $13
   37    37        INIT_FCALL                                               'ob_end_clean'
         38        DO_ICALL                                                 
   39    39        INIT_FCALL                                               'it'
   40    40        SEND_VAL                                                 'calls+event+listeners+in+the+right+order'
   41    41        IS_IDENTICAL                                     ~16     !0, 'event%2C+dataX%2C+priority+10%3Bevent%2C+dataX%2C+priority+0%3Bother_event%2C+dataY+priority+5%3Bother_event%2C+dataY%2C+priority+-5%3B'
         42        SEND_VAL                                                 ~16
         43        DO_FCALL                                      0          
   59    44        INIT_FCALL                                               'ob_start'
         45        DO_ICALL                                                 
   60    46        NEW                                              $19     'Foo'
         47        BEGIN_SILENCE                                    ~20     
         48        FETCH_CONSTANT                                   ~21     'e'
         49        END_SILENCE                                              ~20
         50        SEND_VAL_EX                                              ~21
         51        DO_FCALL                                      0          
         52        ASSIGN                                                   !1, $19
   61    53        INIT_FCALL                                               'e'
         54        SEND_VAL                                                 'my_event'
         55        SEND_VAL                                                 5
         56        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FeJhvp%3A61%244'
         57        SEND_VAL                                                 ~24
         58        DO_FCALL                                      0          
   62    59        INIT_METHOD_CALL                                         !1, 'doStuff'
         60        DO_FCALL                                      0          
   63    61        INIT_FCALL                                               'ob_get_contents'
         62        DO_ICALL                                         $27     
         63        ASSIGN                                                   !0, $27
         64        INIT_FCALL                                               'ob_end_clean'
         65        DO_ICALL                                                 
   65    66        INIT_FCALL                                               'it'
   66    67        SEND_VAL                                                 'is+perfectly+possible+to+inject+the+event+dispatcher+as+a+dependency+into+classes.'
   67    68        IS_IDENTICAL                                     ~30     !0, 'My+event+was+called+with+%27my+data%27'
         69        SEND_VAL                                                 ~30
         70        DO_FCALL                                      0          
   68    71      > RETURN                                                   1

Function e:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 27
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 27
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 25
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/eJhvp
function name:  e
number of ops:  29
compiled vars:  !0 = $n, !1 = $p, !2 = $c, !3 = $a, !4 = $q, !5 = $r
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    1     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      0
          3        BIND_STATIC                                              !3
          4        BEGIN_SILENCE                                    ~6      
          5        INIT_FCALL                                               'krsort'
          6        FETCH_DIM_W                                      $7      !3, !0
          7        SEND_REF                                                 $7
          8        DO_ICALL                                                 
          9        END_SILENCE                                              ~6
         10      > JMPZ                                                     !2, ->16
         11    >   FETCH_DIM_W                                      $9      !3, !0
         12        FETCH_DIM_W                                      $10     $9, !1
         13        ASSIGN_DIM                                               $10
         14        OP_DATA                                                  !2
         15      > JMP                                                      ->28
         16    >   FETCH_DIM_R                                      ~12     !3, !0
         17      > FE_RESET_R                                       $13     ~12, ->27
         18    > > FE_FETCH_R                                               $13, !4, ->27
         19    > > FE_RESET_R                                       $14     !4, ->25
         20    > > FE_FETCH_R                                               $14, !5, ->25
         21    >   INIT_DYNAMIC_CALL                                        !5
         22        SEND_VAR_EX                                              !1
         23        DO_FCALL                                      0          
         24      > JMP                                                      ->20
         25    >   FE_FREE                                                  $14
         26      > JMP                                                      ->18
         27    >   FE_FREE                                                  $13
         28    > > RETURN                                                   null

End of function e

Function it:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
Branch analysis from position: 16
filename:       /in/eJhvp
function name:  it
number of ops:  17
compiled vars:  !0 = $m, !1 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2      > JMPZ                                                     !1, ->5
          3    >   QM_ASSIGN                                        ~2      '%E2%9C%94%EF%B8%8E'
          4      > JMP                                                      ->6
          5    >   QM_ASSIGN                                        ~2      '%E2%9C%98'
          6    >   ROPE_INIT                                     3  ~4      '+It+'
          7        ROPE_ADD                                      1  ~4      ~4, !0
          8        ROPE_END                                      2  ~3      ~4, '%0A'
          9        CONCAT                                           ~6      ~2, ~3
         10        ECHO                                                     ~6
         11        BOOL_NOT                                         ~7      !1
         12      > JMPZ                                                     ~7, ->16
         13    >   FETCH_W                      global              $8      'GLOBALS'
         14        ASSIGN_DIM                                               $8, 'f'
         15        OP_DATA                                                  1
         16    > > RETURN                                                   null

End of function it

Function done:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eJhvp
function name:  done
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
          0  E >   BEGIN_SILENCE                                    ~0      
          1        FETCH_R                      global              ~1      'GLOBALS'
          2        FETCH_DIM_R                                      ~2      ~1, 'f'
          3        END_SILENCE                                              ~0
          4      > JMPZ                                                     ~2, ->6
          5    > > EXIT                                                     1
          6    > > RETURN                                                   null

End of function done

Function %00%7Bclosure%7D%2Fin%2FeJhvp%3A9%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eJhvp
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        ROPE_INIT                                     3  ~2      'event%2C+'
          2        ROPE_ADD                                      1  ~2      ~2, !0
          3        ROPE_END                                      2  ~1      ~2, '%2C+priority+0%3B'
          4        ECHO                                                     ~1
   11     5      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FeJhvp%3A9%240

Function %00%7Bclosure%7D%2Fin%2FeJhvp%3A16%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eJhvp
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        ROPE_INIT                                     3  ~2      'event%2C+'
          2        ROPE_ADD                                      1  ~2      ~2, !0
          3        ROPE_END                                      2  ~1      ~2, '%2C+priority+10%3B'
          4        ECHO                                                     ~1
   18     5      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FeJhvp%3A16%241

Function %00%7Bclosure%7D%2Fin%2FeJhvp%3A23%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eJhvp
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   24     1        ROPE_INIT                                     3  ~2      'other_event%2C+'
          2        ROPE_ADD                                      1  ~2      ~2, !0
          3        ROPE_END                                      2  ~1      ~2, '%2C+priority+-5%3B'
          4        ECHO                                                     ~1
   25     5      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FeJhvp%3A23%242

Function %00%7Bclosure%7D%2Fin%2FeJhvp%3A30%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eJhvp
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
   31     1        ROPE_INIT                                     3  ~2      'other_event%2C+'
          2        ROPE_ADD                                      1  ~2      ~2, !0
          3        ROPE_END                                      2  ~1      ~2, '+priority+5%3B'
          4        ECHO                                                     ~1
   32     5      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FeJhvp%3A30%243

Function %00%7Bclosure%7D%2Fin%2FeJhvp%3A61%244:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eJhvp
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   RECV                                             !0      
          1        ROPE_INIT                                     3  ~2      'My+event+was+called+with+%27'
          2        ROPE_ADD                                      1  ~2      ~2, !0
          3        ROPE_END                                      2  ~1      ~2, '%27'
          4        ECHO                                                     ~1
          5      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FeJhvp%3A61%244

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

End of function __construct

Function dostuff:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eJhvp
function name:  doStuff
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   FETCH_OBJ_R                                      ~0      'eventDispatcher'
          1        INIT_USER_CALL                                2          'call_user_func', ~0
          2        SEND_USER                                                'my_event'
          3        SEND_USER                                                'my+data'
          4        DO_FCALL                                      0          
   56     5      > RETURN                                                   null

End of function dostuff

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.73 ms | 1418 KiB | 32 Q