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

End of function url_replace

Function %00%7Bclosure%7D%2Fin%2F9Fq0U%3A79%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9Fq0U
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                                                   'bar%40example.com'
   81     2*     > RETURN                                                   null

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.77 ms | 1407 KiB | 16 Q