3v4l.org

run code in 500+ PHP versions simultaneously
<?php /** * @see: https://stackoverflow.com/a/47374090/2377961 */ class Hook { protected static $hooks = array(); public function __construct() { return new __Hook(); } public static function on($event, $fn) { self::$hooks[$event][] = $fn; echo "Static click\n"; } } // Hidden class class __Hook { protected $hooks = array(); public function on($event, $fn) { $this->hooks[$event][] = $fn; echo "Non Static click\n"; } } # To call it statically: Hook::on("click", function() {}); # To call it dynamically: $hook = new Hook; $hook->on("click", function() {});
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HIBKR
function name:  (null)
number of ops:  14
compiled vars:  !0 = $hook
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   41     0  E >   INIT_STATIC_METHOD_CALL                                      'Hook', 'on'
          1        SEND_VAL                                                     'click'
          2        DECLARE_LAMBDA_FUNCTION                              ~1      [0]
          3        SEND_VAL                                                     ~1
          4        DO_FCALL                                          0          
   45     5        NEW                                                  $3      'Hook'
          6        DO_FCALL                                          0          
          7        ASSIGN                                                       !0, $3
   46     8        INIT_METHOD_CALL                                             !0, 'on'
          9        SEND_VAL_EX                                                  'click'
         10        DECLARE_LAMBDA_FUNCTION                              ~6      [1]
         11        SEND_VAL_EX                                                  ~6
         12        DO_FCALL                                          0          
         13      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HIBKR
function name:  {closure:/in/HIBKR:41}
number of ops:  1
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   41     0  E > > RETURN                                                       null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HIBKR
function name:  {closure:/in/HIBKR:46}
number of ops:  1
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   46     0  E > > RETURN                                                       null

End of Dynamic Function 1

Class Hook:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HIBKR
function name:  __construct
number of ops:  4
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   11     0  E >   NEW                                                  $0      '__Hook'
          1        DO_FCALL                                          0          
          2      > RETURN                                                       $0
   12     3*     > RETURN                                                       null

End of function __construct

Function on:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HIBKR
function name:  on
number of ops:  8
compiled vars:  !0 = $event, !1 = $fn
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   15     2        FETCH_STATIC_PROP_W              global              $2      'hooks'
          3        FETCH_DIM_W                                          $3      $2, !0
          4        ASSIGN_DIM                                                   $3
          5        OP_DATA                                                      !1
   16     6        ECHO                                                         'Static+click%0A'
   17     7      > RETURN                                                       null

End of function on

End of class Hook.

Class __Hook:
Function on:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HIBKR
function name:  on
number of ops:  8
compiled vars:  !0 = $event, !1 = $fn
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   28     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   29     2        FETCH_OBJ_W                                          $2      'hooks'
          3        FETCH_DIM_W                                          $3      $2, !0
          4        ASSIGN_DIM                                                   $3
          5        OP_DATA                                                      !1
   30     6        ECHO                                                         'Non+Static+click%0A'
   31     7      > RETURN                                                       null

End of function on

End of class __Hook.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
232.01 ms | 3359 KiB | 13 Q