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; } } 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"; foreach(array(100) as $base) { sM::addMethod('add'.$base, function($self, $number) use ($base) { return $self->add($number, $base); }); } 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 = 21, Position 2 = 30
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 30
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/5V1EJ
function name:  (null)
number of ops:  42
compiled vars:  !0 = $base, !1 = $sM
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   INIT_STATIC_METHOD_CALL                                  'sM', 'addMethod'
          1        CONCAT                                           ~2      'add', !0
          2        SEND_VAL                                                 ~2
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F5V1EJ%3A25%240'
          4        BIND_LEXICAL                                             ~3, !0
   27     5        SEND_VAL                                                 ~3
          6        DO_FCALL                                      0          
   29     7        NEW                                              $5      'sM'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $5
   31    10        INIT_METHOD_CALL                                         !1, 'add10'
         11        SEND_VAL_EX                                              1
         12        DO_FCALL                                      0  $8      
         13        CONCAT                                           ~9      $8, '%0A'
         14        ECHO                                                     ~9
   32    15        INIT_METHOD_CALL                                         !1, 'add100'
         16        SEND_VAL_EX                                              1
         17        DO_FCALL                                      0  $10     
         18        CONCAT                                           ~11     $10, '%0A'
         19        ECHO                                                     ~11
   34    20      > FE_RESET_R                                       $12     <array>, ->30
         21    > > FE_FETCH_R                                               $12, !0, ->30
   35    22    >   INIT_STATIC_METHOD_CALL                                  'sM', 'addMethod'
         23        CONCAT                                           ~13     'add', !0
         24        SEND_VAL                                                 ~13
         25        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F5V1EJ%3A35%241'
         26        BIND_LEXICAL                                             ~14, !0
   37    27        SEND_VAL                                                 ~14
         28        DO_FCALL                                      0          
   34    29      > JMP                                                      ->21
         30    >   FE_FREE                                                  $12
   40    31        INIT_METHOD_CALL                                         !1, 'add100'
         32        SEND_VAL_EX                                              1
         33        DO_FCALL                                      0  $16     
         34        CONCAT                                           ~17     $16, '%0A'
         35        ECHO                                                     ~17
   42    36        INIT_METHOD_CALL                                         !1, 'add1000'
         37        SEND_VAL_EX                                              1
         38        DO_FCALL                                      0  $18     
         39        CONCAT                                           ~19     $18, '%0A'
         40        ECHO                                                     ~19
         41      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F5V1EJ%3A25%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5V1EJ
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%2F5V1EJ%3A25%240

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

End of function %00%7Bclosure%7D%2Fin%2F5V1EJ%3A35%241

Class sM:
Function addmethod:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5V1EJ
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/5V1EJ
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/5V1EJ
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:
173.25 ms | 1404 KiB | 15 Q