3v4l.org

run code in 500+ 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 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 31
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 31
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 31
Branch analysis from position: 23
Branch analysis from position: 31
filename:       /in/M5t7X
function name:  args_to_assoc_array
number of ops:  34
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        FRAMELESS_ICALL_2                strpos              ~6      !0, '%3A%3A'
          3        TYPE_CHECK                                        4          ~6
          4      > JMPZ                                                         ~7, ->10
    5     5    >   NEW                                                  $8      'ReflectionFunction'
          6        SEND_VAR_EX                                                  !0
          7        DO_FCALL                                          0          
          8        ASSIGN                                                       !2, $8
    4     9      > JMP                                                          ->19
    7    10    >   NEW                                                  $11     'ReflectionMethod'
         11        INIT_FCALL                                                   'explode'
         12        SEND_VAL                                                     '%3A%3A'
         13        SEND_VAR                                                     !0
         14        DO_ICALL                                             $12     
         15        SEND_UNPACK                                                  $12
         16        CHECK_UNDEF_ARGS                                             
         17        DO_FCALL                                          1          
         18        ASSIGN                                                       !2, $11
    9    19    >   ASSIGN                                                       !3, <array>
   10    20        INIT_METHOD_CALL                                             !2, 'getParameters'
         21        DO_FCALL                                          0  $16     
         22      > FE_RESET_R                                           $17     $16, ->31
         23    > > FE_FETCH_R                                           ~18     $17, !4, ->31
         24    >   ASSIGN                                                       !5, ~18
   11    25        INIT_METHOD_CALL                                             !4, 'getName'
         26        DO_FCALL                                          0  $20     
         27        FETCH_DIM_R                                          ~22     !1, !5
         28        ASSIGN_DIM                                                   !3, $20
         29        OP_DATA                                                      ~22
   10    30      > JMP                                                          ->23
         31    >   FE_FREE                                                      $17
   13    32      > RETURN                                                       !3
   14    33*     > 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.5.0


preferences:
163.72 ms | 2125 KiB | 18 Q