3v4l.org

run code in 500+ PHP versions simultaneously
<?php function getRegexUri(string $uri): string { return '#^' . \preg_replace_callback( '/\/\{(\??)([a-zA-Z_][a-zA-Z0-9_]*)(?::([^}]+)|<([^>]+)>)?}/', function (array $matches): string { $regex = $matches[3] ?? null; $type = $matches[4] ?? null; if ($regex === '') { $regex = null; } $pattern = $regex ?? $this->patterns->get($type ?? '')->regex ?? '[^/]+'; $segment = '(?<' . $matches[2] . '>' . $pattern . ')'; return $matches[1] === '?' ? '(?:/' . $segment . ')?' : '/' . $segment; }, $uri, ) . '$#'; } $v = '/test-http-{code:\d+}/'; var_dump(getRegexUri($v));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ef3eH
function name:  (null)
number of ops:  8
compiled vars:  !0 = $v
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                       !0, '%2Ftest-http-%7Bcode%3A%5Cd%2B%7D%2F'
   28     1        INIT_FCALL                                                   'var_dump'
          2        INIT_FCALL                                                   'getregexuri'
          3        SEND_VAR                                                     !0
          4        DO_FCALL                                          0  $2      
          5        SEND_VAR                                                     $2
          6        DO_ICALL                                                     
          7      > RETURN                                                       1

Function getregexuri:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ef3eH
function name:  getRegexUri
number of ops:  13
compiled vars:  !0 = $uri
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    5     1        INIT_FCALL                                                   'preg_replace_callback'
    6     2        SEND_VAL                                                     '%2F%5C%2F%5C%7B%28%5C%3F%3F%29%28%5Ba-zA-Z_%5D%5Ba-zA-Z0-9_%5D%2A%29%28%3F%3A%3A%28%5B%5E%7D%5D%2B%29%7C%3C%28%5B%5E%3E%5D%2B%29%3E%29%3F%7D%2F'
    7     3        DECLARE_LAMBDA_FUNCTION                              ~1      [0]
   21     4        SEND_VAL                                                     ~1
   22     5        SEND_VAR                                                     !0
    5     6        DO_ICALL                                             $2      
   22     7        CONCAT                                               ~3      '%23%5E', $2
   23     8        CONCAT                                               ~4      ~3, '%24%23'
          9        VERIFY_RETURN_TYPE                                           ~4
         10      > RETURN                                                       ~4
   24    11*       VERIFY_RETURN_TYPE                                           
         12*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 38
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/Ef3eH
function name:  {closure:getRegexUri():7}
number of ops:  44
compiled vars:  !0 = $matches, !1 = $regex, !2 = $type, !3 = $pattern, !4 = $segment
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
    8     1        FETCH_DIM_IS                                         ~5      !0, 3
          2        COALESCE                                             ~6      ~5
          3        QM_ASSIGN                                            ~6      null
          4        ASSIGN                                                       !1, ~6
    9     5        FETCH_DIM_IS                                         ~8      !0, 4
          6        COALESCE                                             ~9      ~8
          7        QM_ASSIGN                                            ~9      null
          8        ASSIGN                                                       !2, ~9
   11     9        IS_IDENTICAL                                                 !1, ''
         10      > JMPZ                                                         ~11, ->12
   12    11    >   ASSIGN                                                       !1, null
   15    12    >   COALESCE                                             ~13     !1
         13        FETCH_THIS                                           $14     
         14        FETCH_OBJ_R                                          ~15     $14, 'patterns'
         15        INIT_METHOD_CALL                                             ~15, 'get'
         16        COALESCE                                             ~16     !2
         17        QM_ASSIGN                                            ~16     ''
         18        SEND_VAL_EX                                                  ~16
         19        DO_FCALL                                          0  $17     
         20        FETCH_OBJ_IS                                         ~18     $17, 'regex'
         21        COALESCE                                             ~19     ~18
         22        QM_ASSIGN                                            ~19     '%5B%5E%2F%5D%2B'
         23        QM_ASSIGN                                            ~13     ~19
         24        ASSIGN                                                       !3, ~13
   16    25        FETCH_DIM_R                                          ~21     !0, 2
         26        CONCAT                                               ~22     '%28%3F%3C', ~21
         27        CONCAT                                               ~23     ~22, '%3E'
         28        CONCAT                                               ~24     ~23, !3
         29        CONCAT                                               ~25     ~24, '%29'
         30        ASSIGN                                                       !4, ~25
   18    31        FETCH_DIM_R                                          ~27     !0, 1
         32        IS_IDENTICAL                                                 ~27, '%3F'
         33      > JMPZ                                                         ~28, ->38
   19    34    >   CONCAT                                               ~29     '%28%3F%3A%2F', !4
         35        CONCAT                                               ~30     ~29, '%29%3F'
         36        QM_ASSIGN                                            ~31     ~30
         37      > JMP                                                          ->40
   20    38    >   CONCAT                                               ~32     '%2F', !4
         39        QM_ASSIGN                                            ~31     ~32
         40    >   VERIFY_RETURN_TYPE                                           ~31
         41      > RETURN                                                       ~31
   21    42*       VERIFY_RETURN_TYPE                                           
         43*     > RETURN                                                       null

End of Dynamic Function 0

End of function getregexuri

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
172.62 ms | 3346 KiB | 16 Q