3v4l.org

run code in 300+ PHP versions simultaneously
<?php function extractRouteParameterComponents($routeParameter) { $regexPattern = "/^{(\w+)(?::(.+))?}(\?)?$/"; if (preg_match($regexPattern, $routeParameter, $matches)) { // This group always exists $name = $matches[1]; // If the group was not present, we use [^/] as a default $pattern = empty($matches[2]) ? "[^/]" : $matches[2]; // The parameter is optional if the last capturing group // (which is a plain question mark) was found $optional = isset($matches[3]); return [$name, $pattern, $optional]; } } $routeParameter = "{id:[0-9]+}?"; list($name, $pattern, $optional) = extractRouteParameterComponents($routeParameter); var_dump($name, $pattern, $optional);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/p0b59
function name:  (null)
number of ops:  17
compiled vars:  !0 = $routeParameter, !1 = $name, !2 = $pattern, !3 = $optional
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, '%7Bid%3A%5B0-9%5D%2B%7D%3F'
   22     1        INIT_FCALL                                               'extractrouteparametercomponents'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $5      
          4        FETCH_LIST_R                                     $6      $5, 0
          5        ASSIGN                                                   !1, $6
          6        FETCH_LIST_R                                     $8      $5, 1
          7        ASSIGN                                                   !2, $8
          8        FETCH_LIST_R                                     $10     $5, 2
          9        ASSIGN                                                   !3, $10
         10        FREE                                                     $5
   24    11        INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !1
         13        SEND_VAR                                                 !2
         14        SEND_VAR                                                 !3
         15        DO_ICALL                                                 
         16      > RETURN                                                   1

Function extractrouteparametercomponents:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 23
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/p0b59
function name:  extractRouteParameterComponents
number of ops:  24
compiled vars:  !0 = $routeParameter, !1 = $regexPattern, !2 = $matches, !3 = $name, !4 = $pattern, !5 = $optional
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, '%2F%5E%7B%28%5Cw%2B%29%28%3F%3A%3A%28.%2B%29%29%3F%7D%28%5C%3F%29%3F%24%2F'
    6     2        INIT_FCALL                                               'preg_match'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        SEND_REF                                                 !2
          6        DO_ICALL                                         $7      
          7      > JMPZ                                                     $7, ->23
    8     8    >   FETCH_DIM_R                                      ~8      !2, 1
          9        ASSIGN                                                   !3, ~8
   11    10        ISSET_ISEMPTY_DIM_OBJ                         1          !2, 2
         11      > JMPZ                                                     ~10, ->14
         12    >   QM_ASSIGN                                        ~11     '%5B%5E%2F%5D'
         13      > JMP                                                      ->16
         14    >   FETCH_DIM_R                                      ~12     !2, 2
         15        QM_ASSIGN                                        ~11     ~12
         16    >   ASSIGN                                                   !4, ~11
   15    17        ISSET_ISEMPTY_DIM_OBJ                         0  ~14     !2, 3
         18        ASSIGN                                                   !5, ~14
   17    19        INIT_ARRAY                                       ~16     !3
         20        ADD_ARRAY_ELEMENT                                ~16     !4
         21        ADD_ARRAY_ELEMENT                                ~16     !5
         22      > RETURN                                                   ~16
   19    23    > > RETURN                                                   null

End of function extractrouteparametercomponents

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.45 ms | 1403 KiB | 18 Q