3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function extractRouteParameterComponents($routeParameter) { $regexPattern = "/^{(\w+)(?::(.+))?}(\?)?$/"; if (preg_match($regexPattern, $routeParameter, $matches)) { $name = $matches[1]; $type = $matches[2] ?? "[^/]"; $optional = isset($matches[3]); return [$name, $type, $optional]; } } $routeParameter = "{id:[0-9]+}"; $parameterComponents = extractRouteParameterComponents($routeParameter); var_dump($parameterComponents);
based on n4YLg
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/YmN6B
function name:  (null)
number of ops:  10
compiled vars:  !0 = $routeParameter, !1 = $parameterComponents
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   NOP                                                      
  15     1        ASSIGN                                                   !0, '%7Bid%3A%5B0-9%5D%2B%7D'
  16     2        INIT_FCALL                                               'extractrouteparametercomponents'
         3        SEND_VAR                                                 !0
         4        DO_FCALL                                      0  $3      
         5        ASSIGN                                                   !1, $3
  18     6        INIT_FCALL                                               'var_dump'
         7        SEND_VAR                                                 !1
         8        DO_ICALL                                                 
         9      > RETURN                                                   1

Function extractrouteparametercomponents:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 8, Position 2 = 20
Branch analysis from position: 8
Jump found. Position 1 = -2
Branch analysis from position: 20
Jump found. Position 1 = -2
filename:       /in/YmN6B
function name:  extractRouteParameterComponents
number of ops:  21
compiled vars:  !0 = $routeParameter, !1 = $regexPattern, !2 = $matches, !3 = $name, !4 = $type, !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, ->20
   7     8    >   FETCH_DIM_R                                      $8      !2, 1
         9        ASSIGN                                                   !3, $8
   8    10        FETCH_DIM_IS                                     $10     !2, 2
        11        COALESCE                                         ~11     $10
        12        QM_ASSIGN                                        ~11     '%5B%5E%2F%5D'
        13        ASSIGN                                                   !4, ~11
   9    14        ISSET_ISEMPTY_DIM_OBJ                       33554432  ~13     !2, 3
        15        ASSIGN                                                   !5, ~13
  11    16        INIT_ARRAY                                       ~15     !3
        17        ADD_ARRAY_ELEMENT                                ~15     !4
        18        ADD_ARRAY_ELEMENT                                ~15     !5
        19      > RETURN                                                   ~15
  13    20    > > RETURN                                                   null

End of function extractrouteparametercomponents

Generated using Vulcan Logic Dumper, using php 7.1.0