3v4l.org

run code in 500+ PHP versions simultaneously
<?php function ghost_func_num_args(string $class, string $method, array $vars = []) { return count(ghost_func_get_args($class, $method, $vars)); } function ghost_func_get_args(string $class, string $method, array $vars = []) { $argc = 0; $argv = []; $reflectionMethod = new ReflectionMethod($class, $method); foreach ($reflectionMethod->getParameters() as $parameter) { $name = $parameter->getName(); $values = $vars[$name] ?? null; if (! $parameter->isVariadic()) { $argv[$parameter->getPosition()] = $values; ++$argc; continue; } foreach ($values as $value) { $argv[$argc++] = $value; } } return $argv; } function ghost_func_get_named_args(string $class, string $method, array $vars = []) { $argv_named = []; $reflectionMethod = new ReflectionMethod($class, $method); foreach ($reflectionMethod->getParameters() as $parameter) { $name = $parameter->getName(); $values = $vars[$name] ?? null; if (! $parameter->isVariadic()) { $argv_named[$name] = $values; continue; } foreach ($values as $key => $value) { $argv_named[$key] = $value; } } return $argv_named; } class User { public function register($email, $password, $active = null, $default = 0, ...$attributes) { $__mockery__vars = get_defined_vars(); $argc = ghost_func_num_args(__CLASS__, __FUNCTION__, $__mockery__vars); $argv = ghost_func_get_args(__CLASS__, __FUNCTION__, $__mockery__vars); $argv_named = ghost_func_get_named_args(__CLASS__, __FUNCTION__, $__mockery__vars); print_r([ '$argc' => $argc, '$argv' => $argv, '$argv_named' => $argv_named, ]); return [$email, $password, $attributes]; } } $foo = new User(); $foo->register('admin@test.com', 'pass1', ...[ 'id' => 'uuid-1', 'phone' => '012-345-6789', 'role' => 'admin', ]); echo PHP_EOL . '--------' . PHP_EOL; $foo->register(...[ 'id' => 'uuid-2', 'email' => 'test@test.com', 'phone' => '987-654-3210', 'name' => 'first last2', 'role' => 'tester', 'password' => 'pass2' ]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UvZt8
function name:  (null)
number of ops:  15
compiled vars:  !0 = $foo
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   71     0  E >   NEW                                                  $1      'User'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $1
   73     3        INIT_METHOD_CALL                                             !0, 'register'
          4        SEND_VAL_EX                                                  'admin%40test.com'
          5        SEND_VAL_EX                                                  'pass1'
   74     6        SEND_UNPACK                                                  <array>
          7        CHECK_UNDEF_ARGS                                             
   73     8        DO_FCALL                                          1          
   79     9        ECHO                                                         '%0A--------%0A'
   81    10        INIT_METHOD_CALL                                             !0, 'register'
   82    11        SEND_UNPACK                                                  <array>
         12        CHECK_UNDEF_ARGS                                             
   81    13        DO_FCALL                                          1          
   88    14      > RETURN                                                       1

Function ghost_func_num_args:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UvZt8
function name:  ghost_func_num_args
number of ops:  11
compiled vars:  !0 = $class, !1 = $method, !2 = $vars
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV_INIT                                            !2      <array>
    5     3        INIT_FCALL_BY_NAME                                           'ghost_func_get_args'
          4        SEND_VAR_EX                                                  !0
          5        SEND_VAR_EX                                                  !1
          6        SEND_VAR_EX                                                  !2
          7        DO_FCALL                                          0  $3      
          8        COUNT                                                ~4      $3
          9      > RETURN                                                       ~4
    6    10*     > RETURN                                                       null

End of function ghost_func_num_args

Function ghost_func_get_args:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 39
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 39
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 31
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 31
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 37
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 37
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 37
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/UvZt8
function name:  ghost_func_get_args
number of ops:  42
compiled vars:  !0 = $class, !1 = $method, !2 = $vars, !3 = $argc, !4 = $argv, !5 = $reflectionMethod, !6 = $parameter, !7 = $name, !8 = $values, !9 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV_INIT                                            !2      <array>
    9     3        ASSIGN                                                       !3, 0
   10     4        ASSIGN                                                       !4, <array>
   11     5        NEW                                                  $12     'ReflectionMethod'
          6        SEND_VAR_EX                                                  !0
          7        SEND_VAR_EX                                                  !1
          8        DO_FCALL                                          0          
          9        ASSIGN                                                       !5, $12
   12    10        INIT_METHOD_CALL                                             !5, 'getParameters'
         11        DO_FCALL                                          0  $15     
         12      > FE_RESET_R                                           $16     $15, ->39
         13    > > FE_FETCH_R                                                   $16, !6, ->39
   13    14    >   INIT_METHOD_CALL                                             !6, 'getName'
         15        DO_FCALL                                          0  $17     
         16        ASSIGN                                                       !7, $17
   14    17        FETCH_DIM_IS                                         ~19     !2, !7
         18        COALESCE                                             ~20     ~19
         19        QM_ASSIGN                                            ~20     null
         20        ASSIGN                                                       !8, ~20
   16    21        INIT_METHOD_CALL                                             !6, 'isVariadic'
         22        DO_FCALL                                          0  $22     
         23        BOOL_NOT                                             ~23     $22
         24      > JMPZ                                                         ~23, ->31
   17    25    >   INIT_METHOD_CALL                                             !6, 'getPosition'
         26        DO_FCALL                                          0  $24     
         27        ASSIGN_DIM                                                   !4, $24
         28        OP_DATA                                                      !8
   18    29        PRE_INC                                                      !3
   19    30      > JMP                                                          ->13
   22    31    > > FE_RESET_R                                           $27     !8, ->37
         32    > > FE_FETCH_R                                                   $27, !9, ->37
   23    33    >   POST_INC                                             ~28     !3
         34        ASSIGN_DIM                                                   !4, ~28
         35        OP_DATA                                                      !9
   22    36      > JMP                                                          ->32
         37    >   FE_FREE                                                      $27
   12    38      > JMP                                                          ->13
         39    >   FE_FREE                                                      $16
   27    40      > RETURN                                                       !4
   28    41*     > RETURN                                                       null

End of function ghost_func_get_args

Function ghost_func_get_named_args:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 35
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 35
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 27
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 27
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 33
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 33
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 33
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/UvZt8
function name:  ghost_func_get_named_args
number of ops:  38
compiled vars:  !0 = $class, !1 = $method, !2 = $vars, !3 = $argv_named, !4 = $reflectionMethod, !5 = $parameter, !6 = $name, !7 = $values, !8 = $value, !9 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   30     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV_INIT                                            !2      <array>
   32     3        ASSIGN                                                       !3, <array>
   33     4        NEW                                                  $11     'ReflectionMethod'
          5        SEND_VAR_EX                                                  !0
          6        SEND_VAR_EX                                                  !1
          7        DO_FCALL                                          0          
          8        ASSIGN                                                       !4, $11
   34     9        INIT_METHOD_CALL                                             !4, 'getParameters'
         10        DO_FCALL                                          0  $14     
         11      > FE_RESET_R                                           $15     $14, ->35
         12    > > FE_FETCH_R                                                   $15, !5, ->35
   35    13    >   INIT_METHOD_CALL                                             !5, 'getName'
         14        DO_FCALL                                          0  $16     
         15        ASSIGN                                                       !6, $16
   36    16        FETCH_DIM_IS                                         ~18     !2, !6
         17        COALESCE                                             ~19     ~18
         18        QM_ASSIGN                                            ~19     null
         19        ASSIGN                                                       !7, ~19
   38    20        INIT_METHOD_CALL                                             !5, 'isVariadic'
         21        DO_FCALL                                          0  $21     
         22        BOOL_NOT                                             ~22     $21
         23      > JMPZ                                                         ~22, ->27
   39    24    >   ASSIGN_DIM                                                   !3, !6
         25        OP_DATA                                                      !7
   40    26      > JMP                                                          ->12
   43    27    > > FE_RESET_R                                           $24     !7, ->33
         28    > > FE_FETCH_R                                           ~25     $24, !8, ->33
         29    >   ASSIGN                                                       !9, ~25
   44    30        ASSIGN_DIM                                                   !3, !9
         31        OP_DATA                                                      !8
   43    32      > JMP                                                          ->28
         33    >   FE_FREE                                                      $24
   34    34      > JMP                                                          ->12
         35    >   FE_FREE                                                      $15
   48    36      > RETURN                                                       !3
   49    37*     > RETURN                                                       null

End of function ghost_func_get_named_args

Class User:
Function register:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UvZt8
function name:  register
number of ops:  37
compiled vars:  !0 = $email, !1 = $password, !2 = $active, !3 = $default, !4 = $attributes, !5 = $__mockery__vars, !6 = $argc, !7 = $argv, !8 = $argv_named
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   53     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV_INIT                                            !2      null
          3        RECV_INIT                                            !3      0
          4        RECV_VARIADIC                                        !4      
   55     5        INIT_FCALL                                                   'get_defined_vars'
          6        DO_ICALL                                             $9      
          7        ASSIGN                                                       !5, $9
   57     8        INIT_FCALL                                                   'ghost_func_num_args'
          9        SEND_VAL                                                     'User'
         10        SEND_VAL                                                     'register'
         11        SEND_VAR                                                     !5
         12        DO_FCALL                                          0  $11     
         13        ASSIGN                                                       !6, $11
   58    14        INIT_FCALL                                                   'ghost_func_get_args'
         15        SEND_VAL                                                     'User'
         16        SEND_VAL                                                     'register'
         17        SEND_VAR                                                     !5
         18        DO_FCALL                                          0  $13     
         19        ASSIGN                                                       !7, $13
   59    20        INIT_FCALL                                                   'ghost_func_get_named_args'
         21        SEND_VAL                                                     'User'
         22        SEND_VAL                                                     'register'
         23        SEND_VAR                                                     !5
         24        DO_FCALL                                          0  $15     
         25        ASSIGN                                                       !8, $15
   61    26        INIT_FCALL                                                   'print_r'
   62    27        INIT_ARRAY                                           ~17     !6, '%24argc'
   63    28        ADD_ARRAY_ELEMENT                                    ~17     !7, '%24argv'
   64    29        ADD_ARRAY_ELEMENT                                    ~17     !8, '%24argv_named'
         30        SEND_VAL                                                     ~17
   61    31        DO_ICALL                                                     
   67    32        INIT_ARRAY                                           ~19     !0
         33        ADD_ARRAY_ELEMENT                                    ~19     !1
         34        ADD_ARRAY_ELEMENT                                    ~19     !4
         35      > RETURN                                                       ~19
   68    36*     > RETURN                                                       null

End of function register

End of class User.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
160.29 ms | 3015 KiB | 13 Q