3v4l.org

run code in 300+ PHP versions simultaneously
<?php $functionDef = <<<'EOF' <?php function notThisOne( $baz = 'boz') {} function foo ( Bar $bar, Baz $baz = 'string with, comma', $boz = ['something'] ) { } EOF; $function = 'foo'; $argument = 'baz'; if (!preg_match('/function\s+' . preg_quote($function) . '\s*\(\s*(?P<args>.*?)\)/is', $functionDef, $matches)) { throw new RuntimeException('Cound not find parameters for function ' . $function); } $tokens = token_get_all('<?php ' . $matches['args']); // small state machine, better in a class $foundArg = false; $default = ''; while ($token = next($tokens)) { // find the argument first of all if (!$foundArg) { if (is_array($token) && $token[1] == '$'.$argument) { $foundArg = true; } continue; } // detect when we have got to the end of the definitoin if ($token === ',') { break; } // compile everything else into the string if (is_string($token)) { $default .= $token; } else { $default .= $token[1]; } } var_dump($default);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 29
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 40
Branch analysis from position: 31
2 jumps found. (Code = 46) Position 1 = 33, Position 2 = 37
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 39
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 39
Branch analysis from position: 37
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 43
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 47
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 29
Branch analysis from position: 54
Branch analysis from position: 29
filename:       /in/e9odg
function name:  (null)
number of ops:  58
compiled vars:  !0 = $functionDef, !1 = $function, !2 = $argument, !3 = $matches, !4 = $tokens, !5 = $foundArg, !6 = $default, !7 = $token
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3C%3Fphp%0A%0A++function+notThisOne%28+%24baz+%3D+%27boz%27%29+%7B%7D%0A%0A++function+foo+%28+Bar+%24bar%2C+Baz+%24baz+%3D+%27string+with%2C+comma%27%2C+%24boz+%3D+%5B%27something%27%5D+%29+%7B%0A%0A++%7D%0A'
   14     1        ASSIGN                                                   !1, 'foo'
   15     2        ASSIGN                                                   !2, 'baz'
   17     3        INIT_FCALL                                               'preg_match'
          4        INIT_FCALL                                               'preg_quote'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $11     
          7        CONCAT                                           ~12     '%2Ffunction%5Cs%2B', $11
          8        CONCAT                                           ~13     ~12, '%5Cs%2A%5C%28%5Cs%2A%28%3FP%3Cargs%3E.%2A%3F%29%5C%29%2Fis'
          9        SEND_VAL                                                 ~13
         10        SEND_VAR                                                 !0
         11        SEND_REF                                                 !3
         12        DO_ICALL                                         $14     
         13        BOOL_NOT                                         ~15     $14
         14      > JMPZ                                                     ~15, ->20
   18    15    >   NEW                                              $16     'RuntimeException'
         16        CONCAT                                           ~17     'Cound+not+find+parameters+for+function+', !1
         17        SEND_VAL_EX                                              ~17
         18        DO_FCALL                                      0          
         19      > THROW                                         0          $16
   21    20    >   INIT_FCALL                                               'token_get_all'
         21        FETCH_DIM_R                                      ~19     !3, 'args'
         22        CONCAT                                           ~20     '%3C%3Fphp+', ~19
         23        SEND_VAL                                                 ~20
         24        DO_ICALL                                         $21     
         25        ASSIGN                                                   !4, $21
   24    26        ASSIGN                                                   !5, <false>
   25    27        ASSIGN                                                   !6, ''
   26    28      > JMP                                                      ->49
   29    29    >   BOOL_NOT                                         ~25     !5
         30      > JMPZ                                                     ~25, ->40
   30    31    >   TYPE_CHECK                                  128  ~26     !7
         32      > JMPZ_EX                                          ~26     ~26, ->37
         33    >   FETCH_DIM_R                                      ~27     !7, 1
         34        CONCAT                                           ~28     '%24', !2
         35        IS_EQUAL                                         ~29     ~27, ~28
         36        BOOL                                             ~26     ~29
         37    > > JMPZ                                                     ~26, ->39
   31    38    >   ASSIGN                                                   !5, <true>
   33    39    > > JMP                                                      ->49
   37    40    >   IS_IDENTICAL                                             !7, '%2C'
         41      > JMPZ                                                     ~31, ->43
   38    42    > > JMP                                                      ->54
   42    43    >   TYPE_CHECK                                   64          !7
         44      > JMPZ                                                     ~32, ->47
   43    45    >   ASSIGN_OP                                     8          !6, !7
         46      > JMP                                                      ->49
   46    47    >   FETCH_DIM_R                                      ~34     !7, 1
         48        ASSIGN_OP                                     8          !6, ~34
   26    49    >   INIT_FCALL                                               'next'
         50        SEND_REF                                                 !4
         51        DO_ICALL                                         $36     
         52        ASSIGN                                           ~37     !7, $36
         53      > JMPNZ                                                    ~37, ->29
   51    54    >   INIT_FCALL                                               'var_dump'
         55        SEND_VAR                                                 !6
         56        DO_ICALL                                                 
         57      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.17 ms | 1400 KiB | 23 Q