3v4l.org

run code in 300+ PHP versions simultaneously
<?php class sM { static private $_methods = array(); static public function addMethod($name, Closure $cb) { self::$_methods[$name] = $cb; } public function __call($name, array $args) { array_unshift($args, $this); return call_user_func_array(self::$_methods[$name], $args); } public function add($a, $b) { return $a + $b; } } foreach(array(10) as $base) { sM::addMethod('add'.$base, function($self, $number) use ($base) { return $self->add($number, $base); }); } $sM = new sM(); echo $sM->add10(1)."\n"; echo $sM->add100(1)."\n"; echo $sM->add1000(1)."\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 1, Position 2 = 10
Branch analysis from position: 1
2 jumps found. (Code = 78) Position 1 = 2, Position 2 = 10
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 1
Branch analysis from position: 1
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/X0EVG
function name:  (null)
number of ops:  30
compiled vars:  !0 = $base, !1 = $sM
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E > > FE_RESET_R                                       $2      <array>, ->10
          1    > > FE_FETCH_R                                               $2, !0, ->10
   25     2    >   INIT_STATIC_METHOD_CALL                                  'sM', 'addMethod'
          3        CONCAT                                           ~3      'add', !0
          4        SEND_VAL                                                 ~3
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FX0EVG%3A25%240'
          6        BIND_LEXICAL                                             ~4, !0
   27     7        SEND_VAL                                                 ~4
          8        DO_FCALL                                      0          
   24     9      > JMP                                                      ->1
         10    >   FE_FREE                                                  $2
   30    11        NEW                                              $6      'sM'
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !1, $6
   32    14        INIT_METHOD_CALL                                         !1, 'add10'
         15        SEND_VAL_EX                                              1
         16        DO_FCALL                                      0  $9      
         17        CONCAT                                           ~10     $9, '%0A'
         18        ECHO                                                     ~10
   33    19        INIT_METHOD_CALL                                         !1, 'add100'
         20        SEND_VAL_EX                                              1
         21        DO_FCALL                                      0  $11     
         22        CONCAT                                           ~12     $11, '%0A'
         23        ECHO                                                     ~12
   34    24        INIT_METHOD_CALL                                         !1, 'add1000'
         25        SEND_VAL_EX                                              1
         26        DO_FCALL                                      0  $13     
         27        CONCAT                                           ~14     $13, '%0A'
         28        ECHO                                                     ~14
         29      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FX0EVG%3A25%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/X0EVG
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $self, !1 = $number, !2 = $base
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   26     3        INIT_METHOD_CALL                                         !0, 'add'
          4        SEND_VAR_EX                                              !1
          5        SEND_VAR_EX                                              !2
          6        DO_FCALL                                      0  $3      
          7      > RETURN                                                   $3
   27     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FX0EVG%3A25%240

Class sM:
Function addmethod:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/X0EVG
function name:  addMethod
number of ops:  6
compiled vars:  !0 = $name, !1 = $cb
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        FETCH_STATIC_PROP_W          unknown             $2      '_methods'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   10     5      > RETURN                                                   null

End of function addmethod

Function __call:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/X0EVG
function name:  __call
number of ops:  15
compiled vars:  !0 = $name, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        INIT_FCALL                                               'array_unshift'
          3        SEND_REF                                                 !1
          4        FETCH_THIS                                       ~2      
          5        SEND_VAL                                                 ~2
          6        DO_ICALL                                                 
   15     7        FETCH_STATIC_PROP_R          global lock         ~4      '_methods'
          8        FETCH_DIM_R                                      ~5      ~4, !0
          9        INIT_USER_CALL                                0          'call_user_func_array', ~5
         10        SEND_ARRAY                                               !1
         11        CHECK_UNDEF_ARGS                                         
         12        DO_FCALL                                      0  $6      
         13      > RETURN                                                   $6
   16    14*     > RETURN                                                   null

End of function __call

Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/X0EVG
function name:  add
number of ops:  5
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   20     2        ADD                                              ~2      !0, !1
          3      > RETURN                                                   ~2
   21     4*     > RETURN                                                   null

End of function add

End of class sM.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.12 ms | 1400 KiB | 15 Q