3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Because PHP_URL_* constants are sequential :-( const URL_SCHEME = 0x01; const URL_USER = 0x02; const URL_PASS = 0x04; const URL_HOST = 0x08; const URL_PORT = 0x10; const URL_PATH = 0x20; const URL_QUERY = 0x40; const URL_FRAGMENT = 0x80; function url_replace($url, $component, callable $callback) { $map = [ URL_SCHEME => 'scheme', URL_USER => 'user', URL_PASS => 'pass', URL_HOST => 'host', URL_PORT => 'port', URL_PATH => 'path', URL_QUERY => 'query', URL_FRAGMENT => 'fragment', ]; if (!$parts = parse_url($url)) { return $url; } foreach ($map as $component => $key) { if ($components & $flag) { $parts[$key] = $callback($parts[$key], $component); } } $result = ''; if (isset($parts['scheme'])) { $result = $parts['scheme'] . ':'; } if (isset($parts['host'])) { $result .= '//'; if (isset($parts['user'])) { $result .= $parts['user']; if (isset($parts['pass'])) { $result .= ':' . $parts['pass']; } $result .= '@'; } $result .= $parts['host']; if (isset($parts['port'])) { $result .= ':' . $parts['port']; } } if (isset($parts['path'])) { $result .= $parts['path']; } if (isset($parts['query'])) { $result .= $parts['query']; } if (isset($parts['fragment'])) { $result .= $parts['fragment']; } return $result; } $url = 'http://test.com/test-one,two three?a=b#bla'; echo url_replace($url, URL_PATH, function($path) { return '/foobar'; });
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MWYTM
function name:  (null)
number of ops:  18
compiled vars:  !0 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   DECLARE_CONST                                            'URL_SCHEME', 1
    5     1        DECLARE_CONST                                            'URL_USER', 2
    6     2        DECLARE_CONST                                            'URL_PASS', 4
    7     3        DECLARE_CONST                                            'URL_HOST', 8
    8     4        DECLARE_CONST                                            'URL_PORT', 16
    9     5        DECLARE_CONST                                            'URL_PATH', 32
   10     6        DECLARE_CONST                                            'URL_QUERY', 64
   11     7        DECLARE_CONST                                            'URL_FRAGMENT', 128
   77     8        ASSIGN                                                   !0, 'http%3A%2F%2Ftest.com%2Ftest-one%2Ctwo+three%3Fa%3Db%23bla'
   79     9        INIT_FCALL                                               'url_replace'
         10        SEND_VAR                                                 !0
         11        FETCH_CONSTANT                                   ~2      'URL_PATH'
         12        SEND_VAL                                                 ~2
         13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FMWYTM%3A79%240'
   81    14        SEND_VAL                                                 ~3
         15        DO_FCALL                                      0  $4      
         16        ECHO                                                     $4
         17      > RETURN                                                   1

Function url_replace:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 27
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 41
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 41
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 40
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 40
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 48
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 68
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 61
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 60
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 68
Branch analysis from position: 65
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 72
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 76
Branch analysis from position: 74
2 jumps found. (Code = 43) Position 1 = 78, Position 2 = 80
Branch analysis from position: 78
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
Branch analysis from position: 76
Branch analysis from position: 72
Branch analysis from position: 68
Branch analysis from position: 60
Branch analysis from position: 61
Branch analysis from position: 68
Branch analysis from position: 48
Branch analysis from position: 41
filename:       /in/MWYTM
function name:  url_replace
number of ops:  82
compiled vars:  !0 = $url, !1 = $component, !2 = $callback, !3 = $map, !4 = $parts, !5 = $key, !6 = $components, !7 = $flag, !8 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   16     3        FETCH_CONSTANT                                   ~9      'URL_SCHEME'
          4        INIT_ARRAY                                       ~10     'scheme', ~9
   17     5        FETCH_CONSTANT                                   ~11     'URL_USER'
          6        ADD_ARRAY_ELEMENT                                ~10     'user', ~11
   18     7        FETCH_CONSTANT                                   ~12     'URL_PASS'
          8        ADD_ARRAY_ELEMENT                                ~10     'pass', ~12
   19     9        FETCH_CONSTANT                                   ~13     'URL_HOST'
         10        ADD_ARRAY_ELEMENT                                ~10     'host', ~13
   20    11        FETCH_CONSTANT                                   ~14     'URL_PORT'
         12        ADD_ARRAY_ELEMENT                                ~10     'port', ~14
   21    13        FETCH_CONSTANT                                   ~15     'URL_PATH'
         14        ADD_ARRAY_ELEMENT                                ~10     'path', ~15
   22    15        FETCH_CONSTANT                                   ~16     'URL_QUERY'
         16        ADD_ARRAY_ELEMENT                                ~10     'query', ~16
   23    17        FETCH_CONSTANT                                   ~17     'URL_FRAGMENT'
         18        ADD_ARRAY_ELEMENT                                ~10     'fragment', ~17
   15    19        ASSIGN                                                   !3, ~10
   26    20        INIT_FCALL                                               'parse_url'
         21        SEND_VAR                                                 !0
         22        DO_ICALL                                         $19     
         23        ASSIGN                                           ~20     !4, $19
         24        BOOL_NOT                                         ~21     ~20
         25      > JMPZ                                                     ~21, ->27
   27    26    > > RETURN                                                   !0
   30    27    > > FE_RESET_R                                       $22     !3, ->41
         28    > > FE_FETCH_R                                       ~23     $22, !5, ->41
         29    >   ASSIGN                                                   !1, ~23
   31    30        BW_AND                                           ~25     !6, !7
         31      > JMPZ                                                     ~25, ->40
   32    32    >   INIT_DYNAMIC_CALL                                        !2
         33        CHECK_FUNC_ARG                                           
         34        FETCH_DIM_FUNC_ARG                               $27     !4, !5
         35        SEND_FUNC_ARG                                            $27
         36        SEND_VAR_EX                                              !1
         37        DO_FCALL                                      0  $28     
         38        ASSIGN_DIM                                               !4, !5
         39        OP_DATA                                                  $28
   30    40    > > JMP                                                      ->28
         41    >   FE_FREE                                                  $22
   36    42        ASSIGN                                                   !8, ''
   38    43        ISSET_ISEMPTY_DIM_OBJ                         0          !4, 'scheme'
         44      > JMPZ                                                     ~30, ->48
   39    45    >   FETCH_DIM_R                                      ~31     !4, 'scheme'
         46        CONCAT                                           ~32     ~31, '%3A'
         47        ASSIGN                                                   !8, ~32
   42    48    >   ISSET_ISEMPTY_DIM_OBJ                         0          !4, 'host'
         49      > JMPZ                                                     ~34, ->68
   43    50    >   ASSIGN_OP                                     8          !8, '%2F%2F'
   45    51        ISSET_ISEMPTY_DIM_OBJ                         0          !4, 'user'
         52      > JMPZ                                                     ~36, ->61
   46    53    >   FETCH_DIM_R                                      ~37     !4, 'user'
         54        ASSIGN_OP                                     8          !8, ~37
   48    55        ISSET_ISEMPTY_DIM_OBJ                         0          !4, 'pass'
         56      > JMPZ                                                     ~39, ->60
   49    57    >   FETCH_DIM_R                                      ~40     !4, 'pass'
         58        CONCAT                                           ~41     '%3A', ~40
         59        ASSIGN_OP                                     8          !8, ~41
   52    60    >   ASSIGN_OP                                     8          !8, '%40'
   55    61    >   FETCH_DIM_R                                      ~44     !4, 'host'
         62        ASSIGN_OP                                     8          !8, ~44
   57    63        ISSET_ISEMPTY_DIM_OBJ                         0          !4, 'port'
         64      > JMPZ                                                     ~46, ->68
   58    65    >   FETCH_DIM_R                                      ~47     !4, 'port'
         66        CONCAT                                           ~48     '%3A', ~47
         67        ASSIGN_OP                                     8          !8, ~48
   62    68    >   ISSET_ISEMPTY_DIM_OBJ                         0          !4, 'path'
         69      > JMPZ                                                     ~50, ->72
   63    70    >   FETCH_DIM_R                                      ~51     !4, 'path'
         71        ASSIGN_OP                                     8          !8, ~51
   66    72    >   ISSET_ISEMPTY_DIM_OBJ                         0          !4, 'query'
         73      > JMPZ                                                     ~53, ->76
   67    74    >   FETCH_DIM_R                                      ~54     !4, 'query'
         75        ASSIGN_OP                                     8          !8, ~54
   70    76    >   ISSET_ISEMPTY_DIM_OBJ                         0          !4, 'fragment'
         77      > JMPZ                                                     ~56, ->80
   71    78    >   FETCH_DIM_R                                      ~57     !4, 'fragment'
         79        ASSIGN_OP                                     8          !8, ~57
   74    80    > > RETURN                                                   !8
   75    81*     > RETURN                                                   null

End of function url_replace

Function %00%7Bclosure%7D%2Fin%2FMWYTM%3A79%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MWYTM
function name:  {closure}
number of ops:  3
compiled vars:  !0 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   RECV                                             !0      
   80     1      > RETURN                                                   '%2Ffoobar'
   81     2*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FMWYTM%3A79%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.52 ms | 1407 KiB | 16 Q