3v4l.org

run code in 300+ PHP versions simultaneously
<?php function args_to_assoc_array($function, $args) { if (false === strpos($function, '::')) { $reflection = new ReflectionFunction($function); } else { $reflection = new ReflectionMethod(...explode('::', $function)); } $assoc = []; foreach ($reflection->getParameters() as $i => $parameter) { $assoc[$parameter->getName()] = $args[$i]; } return $assoc; } function f($x, $y) { return args_to_assoc_array(__METHOD__, func_get_args()); } class A { function m($z) { return args_to_assoc_array(__METHOD__, func_get_args()); } } var_dump(f(7, 2), (new A)->m(4));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M5t7X
function name:  (null)
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'f'
          2        SEND_VAL                                                 7
          3        SEND_VAL                                                 2
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        NEW                                              $1      'A'
          7        DO_FCALL                                      0          
          8        INIT_METHOD_CALL                                         $1, 'm'
          9        SEND_VAL_EX                                              4
         10        DO_FCALL                                      0  $3      
         11        SEND_VAR                                                 $3
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Function args_to_assoc_array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 34
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 34
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 34
Branch analysis from position: 26
Branch analysis from position: 34
filename:       /in/M5t7X
function name:  args_to_assoc_array
number of ops:  37
compiled vars:  !0 = $function, !1 = $args, !2 = $reflection, !3 = $assoc, !4 = $parameter, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        INIT_FCALL                                               'strpos'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 '%3A%3A'
          5        DO_ICALL                                         $6      
          6        TYPE_CHECK                                    4          $6
          7      > JMPZ                                                     ~7, ->13
    5     8    >   NEW                                              $8      'ReflectionFunction'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $8
         12      > JMP                                                      ->22
    7    13    >   NEW                                              $11     'ReflectionMethod'
         14        INIT_FCALL                                               'explode'
         15        SEND_VAL                                                 '%3A%3A'
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                         $12     
         18        SEND_UNPACK                                              $12
         19        CHECK_UNDEF_ARGS                                         
         20        DO_FCALL                                      1          
         21        ASSIGN                                                   !2, $11
    9    22    >   ASSIGN                                                   !3, <array>
   10    23        INIT_METHOD_CALL                                         !2, 'getParameters'
         24        DO_FCALL                                      0  $16     
         25      > FE_RESET_R                                       $17     $16, ->34
         26    > > FE_FETCH_R                                       ~18     $17, !4, ->34
         27    >   ASSIGN                                                   !5, ~18
   11    28        INIT_METHOD_CALL                                         !4, 'getName'
         29        DO_FCALL                                      0  $20     
         30        FETCH_DIM_R                                      ~22     !1, !5
         31        ASSIGN_DIM                                               !3, $20
         32        OP_DATA                                                  ~22
   10    33      > JMP                                                      ->26
         34    >   FE_FREE                                                  $17
   13    35      > RETURN                                                   !3
   14    36*     > RETURN                                                   null

End of function args_to_assoc_array

Function f:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M5t7X
function name:  f
number of ops:  9
compiled vars:  !0 = $x, !1 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        INIT_FCALL                                               'args_to_assoc_array'
          3        SEND_VAL                                                 'f'
          4        FUNC_GET_ARGS                                    ~2      
          5        SEND_VAL                                                 ~2
          6        DO_FCALL                                      0  $3      
          7      > RETURN                                                   $3
          8*     > RETURN                                                   null

End of function f

Class A:
Function m:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M5t7X
function name:  m
number of ops:  8
compiled vars:  !0 = $z
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'args_to_assoc_array'
          2        SEND_VAL                                                 'A%3A%3Am'
          3        FUNC_GET_ARGS                                    ~1      
          4        SEND_VAL                                                 ~1
          5        DO_FCALL                                      0  $2      
          6      > RETURN                                                   $2
          7*     > RETURN                                                   null

End of function m

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.18 ms | 1403 KiB | 22 Q