3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); /** * @author Abel de Beer <abel@thispagecannotbefound.com> */ class Slot { /** * @var mixed */ public $listener; /** * @var boolean */ public $once; function __construct($listener, $once) { $this->listener = $listener; $this->once = $once; } } /** * @author Abel de Beer <abel@thispagecannotbefound.com> */ class OnceSignal implements OnceSignalInterface { /** * @var Slot[] */ protected $slots; function __construct() { $this->slots = array(); } public function addOnce($listener) { $this->slots[] = new Slot($listener, true); } public function dispatch() { foreach ($this->slots as $index => $slot) { if ($slot->once) { unset($this->slots[$index]); } $callback = $slot->listener; call_user_func($callback); } } } function myListener() { echo __FILE__.' : '.__LINE__."\n"; } $signal = new OnceSignal(); $signal->addOnce('myListener'); $signal->dispatch();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KkItG
function name:  (null)
number of ops:  13
compiled vars:  !0 = $signal
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 -1
          2        DO_ICALL                                                 
   30     3        DECLARE_CLASS                                            'oncesignal'
   63     4        NEW                                              $2      'OnceSignal'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $2
   64     7        INIT_METHOD_CALL                                         !0, 'addOnce'
          8        SEND_VAL_EX                                              'myListener'
          9        DO_FCALL                                      0          
   65    10        INIT_METHOD_CALL                                         !0, 'dispatch'
         11        DO_FCALL                                      0          
         12      > RETURN                                                   1

Function mylistener:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KkItG
function name:  myListener
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   ECHO                                                     '%2Fin%2FKkItG+%3A+60%0A'
   61     1      > RETURN                                                   null

End of function mylistener

Class Slot:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KkItG
function name:  __construct
number of ops:  7
compiled vars:  !0 = $listener, !1 = $once
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   21     2        ASSIGN_OBJ                                               'listener'
          3        OP_DATA                                                  !0
   22     4        ASSIGN_OBJ                                               'once'
          5        OP_DATA                                                  !1
   23     6      > RETURN                                                   null

End of function __construct

End of class Slot.

Class OnceSignal:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KkItG
function name:  __construct
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   ASSIGN_OBJ                                               'slots'
          1        OP_DATA                                                  <array>
   39     2      > RETURN                                                   null

End of function __construct

Function addonce:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KkItG
function name:  addOnce
number of ops:  9
compiled vars:  !0 = $listener
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
   42     1        NEW                                              $3      'Slot'
          2        SEND_VAR_EX                                              !0
          3        SEND_VAL_EX                                              <true>
          4        DO_FCALL                                      0          
          5        FETCH_OBJ_W                                      $1      'slots'
          6        ASSIGN_DIM                                               $1
          7        OP_DATA                                                  $3
   43     8      > RETURN                                                   null

End of function addonce

Function dispatch:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 13
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 8
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/KkItG
function name:  dispatch
number of ops:  15
compiled vars:  !0 = $slot, !1 = $index, !2 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   FETCH_OBJ_R                                      ~3      'slots'
          1      > FE_RESET_R                                       $4      ~3, ->13
          2    > > FE_FETCH_R                                       ~5      $4, !0, ->13
          3    >   ASSIGN                                                   !1, ~5
   47     4        FETCH_OBJ_R                                      ~7      !0, 'once'
          5      > JMPZ                                                     ~7, ->8
   48     6    >   FETCH_OBJ_UNSET                                  $8      'slots'
          7        UNSET_DIM                                                $8, !1
   51     8    >   FETCH_OBJ_R                                      ~9      !0, 'listener'
          9        ASSIGN                                                   !2, ~9
   53    10        INIT_USER_CALL                                0          'call_user_func', !2
         11        DO_FCALL                                      0          
   46    12      > JMP                                                      ->2
         13    >   FE_FREE                                                  $4
   55    14      > RETURN                                                   null

End of function dispatch

End of class OnceSignal.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.65 ms | 1400 KiB | 15 Q