3v4l.org

run code in 300+ PHP versions simultaneously
<?php function make_absolute_path($a,$b){if((!$c=parse_url($a))||(!$d=parse_url($b))){return FALSE;}if(empty($c['host'])&&!empty($c['path'])&&substr($c['path'],0,2)==='//'){$e=explode('/',ltrim($c['path'],'/'));$c['host']=array_shift($e);$c['path']='/'.implode('/',$e);}if(empty($d['host'])&&!empty($d['path'])&&substr($d['path'],0,2)==='//'){$e=explode('/',ltrim($d['path'],'/'));$d['host']=array_shift($e);$d['path']='/'.implode('/',$e);}if(!empty($d['host'])){return $b;}if(empty($c['host'])){return FALSE;}if(empty($c['path'])){$c['path']='/';}if(empty($c['scheme'])){$c['scheme']='http';}$f=$c['scheme'].'://';if(!empty($c['user'])){$f.=$c['user'];if(!empty($c['pass'])){$f.=":{$c['pass']}";}$f.='@';}$f.=!empty($c['port'])?"{$c['host']}:{$c['port']}":$c['host'];if($b[0]==='/'){$f.=$b;}else if($b[0]==='?'){$f.=$c['path'].$b;}else{$g=rtrim(substr($c['path'],-1)==='/'?trim($c['path']):str_replace('\\','/',dirname(trim($c['path']))),'/');foreach(explode('/',$b)as $h){switch($h){case '':case '.':break;case '..':$g=rtrim(str_replace('\\','/',dirname($g)),'/');break;default:$g.="/$h";break;}}$f.=$g;}return $f;}$i=array(1=>array('arg1'=>'http://www.xxx.com/dir/index.php','arg2'=>'/photos/photo.jpg','expect'=>'http://www.xxx.com/photos/photo.jpg'),array('arg1'=>'http://www.xxx.com/dir/index.php','arg2'=>'/photos/photo.jpg','expect'=>'http://www.xxx.com/photos/photo.jpg'),array('arg1'=>'http://www.xxx.com/dir/index.php','arg2'=>'photos/photo.jpg','expect'=>'http://www.xxx.com/dir/photos/photo.jpg'),array('arg1'=>'http://www.xxx.com/dir/index.php','arg2'=>'./photos/photo.jpg','expect'=>'http://www.xxx.com/dir/photos/photo.jpg'),array('arg1'=>'http://www.xxx.com/dir/index.php','arg2'=>'../photos/photo.jpg','expect'=>'http://www.xxx.com/photos/photo.jpg'),array('arg1'=>'http://www.xxx.com/dir/index.php','arg2'=>'//www.yyy.com/photos/photo.jpg','expect'=>'//www.yyy.com/photos/photo.jpg'),array('arg1'=>'http://www.xxx.com/dir/index.php','arg2'=>'?query=something','expect'=>'http://www.xxx.com/dir/index.php?query=something'),array('arg1'=>'http://www.xxx.com/dir/index.php','arg2'=>'?query=something#fragment','expect'=>'http://www.xxx.com/dir/index.php?query=something#fragment'),array('arg1'=>'http://www.xxx.com/dir/index.php','arg2'=>'/photos/photo.jpg#fragment','expect'=>'http://www.xxx.com/photos/photo.jpg#fragment'),array('arg1'=>'http://www.xxx.com/dir/index.php','arg2'=>'../../photos/photo.jpg','expect'=>'http://www.xxx.com/photos/photo.jpg'),array('arg1'=>'http://www.xxx.com/dir/sub1/sub2/index.php','arg2'=>'../../photo/photo.jpg','expect'=>'http://www.xxx.com/dir/photo/photo.jpg'),array('arg1'=>'//www.xxx.com/dir/index.php','arg2'=>'test?query=something','expect'=>'http://www.xxx.com/dir/test?query=something'));foreach($i as $j=>$k){$f=make_absolute_path($k['arg1'],$k['arg2']);echo" Test #$j (".($f===$k['expect']?'PASS':'FAIL').") Arg 1: {$k['arg1']} Arg 2: {$k['arg2']} Expect: {$k['expect']} Result: $f ";}
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 36
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 36
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/BAeXW
function name:  (null)
number of ops:  38
compiled vars:  !0 = $i, !1 = $k, !2 = $j, !3 = $f
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    1     0  E >   ASSIGN                                                   !0, <array>
          1      > FE_RESET_R                                       $5      !0, ->36
          2    > > FE_FETCH_R                                       ~6      $5, !1, ->36
          3    >   ASSIGN                                                   !2, ~6
          4        INIT_FCALL                                               'make_absolute_path'
          5        FETCH_DIM_R                                      ~8      !1, 'arg1'
          6        SEND_VAL                                                 ~8
          7        FETCH_DIM_R                                      ~9      !1, 'arg2'
          8        SEND_VAL                                                 ~9
          9        DO_FCALL                                      0  $10     
         10        ASSIGN                                                   !3, $10
         11        ROPE_INIT                                     3  ~13     '%0A%09Test+%23'
    2    12        ROPE_ADD                                      1  ~13     ~13, !2
         13        ROPE_END                                      2  ~12     ~13, '+%28'
         14        FETCH_DIM_R                                      ~15     !1, 'expect'
         15        IS_IDENTICAL                                             !3, ~15
         16      > JMPZ                                                     ~16, ->19
         17    >   QM_ASSIGN                                        ~17     'PASS'
         18      > JMP                                                      ->20
         19    >   QM_ASSIGN                                        ~17     'FAIL'
         20    >   CONCAT                                           ~18     ~12, ~17
         21        ROPE_INIT                                     9  ~23     '%29%0A%09++Arg+1%3A+'
    3    22        FETCH_DIM_R                                      ~19     !1, 'arg1'
         23        ROPE_ADD                                      1  ~23     ~23, ~19
         24        ROPE_ADD                                      2  ~23     ~23, '%0A%09++Arg+2%3A+'
    4    25        FETCH_DIM_R                                      ~20     !1, 'arg2'
         26        ROPE_ADD                                      3  ~23     ~23, ~20
         27        ROPE_ADD                                      4  ~23     ~23, '%0A%09+Expect%3A+'
    5    28        FETCH_DIM_R                                      ~21     !1, 'expect'
         29        ROPE_ADD                                      5  ~23     ~23, ~21
         30        ROPE_ADD                                      6  ~23     ~23, '%0A%09+Result%3A+'
    6    31        ROPE_ADD                                      7  ~23     ~23, !3
         32        ROPE_END                                      8  ~22     ~23, '%0A%0A'
         33        CONCAT                                           ~28     ~18, ~22
         34        ECHO                                                     ~28
    1    35      > JMP                                                      ->2
         36    >   FE_FREE                                                  $5
    8    37      > RETURN                                                   1

Function make_absolute_path:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 46) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
2 jumps found. (Code = 46) Position 1 = 22, Position 2 = 30
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 53
Branch analysis from position: 31
2 jumps found. (Code = 46) Position 1 = 55, Position 2 = 58
Branch analysis from position: 55
2 jumps found. (Code = 46) Position 1 = 59, Position 2 = 67
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 68, Position 2 = 90
Branch analysis from position: 68
2 jumps found. (Code = 43) Position 1 = 93, Position 2 = 94
Branch analysis from position: 93
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 94
2 jumps found. (Code = 43) Position 1 = 96, Position 2 = 97
Branch analysis from position: 96
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 97
2 jumps found. (Code = 43) Position 1 = 99, Position 2 = 101
Branch analysis from position: 99
2 jumps found. (Code = 43) Position 1 = 103, Position 2 = 105
Branch analysis from position: 103
2 jumps found. (Code = 43) Position 1 = 111, Position 2 = 121
Branch analysis from position: 111
2 jumps found. (Code = 43) Position 1 = 116, Position 2 = 120
Branch analysis from position: 116
2 jumps found. (Code = 43) Position 1 = 124, Position 2 = 131
Branch analysis from position: 124
1 jumps found. (Code = 42) Position 1 = 133
Branch analysis from position: 133
2 jumps found. (Code = 43) Position 1 = 137, Position 2 = 139
Branch analysis from position: 137
1 jumps found. (Code = 42) Position 1 = 213
Branch analysis from position: 213
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 139
2 jumps found. (Code = 43) Position 1 = 142, Position 2 = 146
Branch analysis from position: 142
1 jumps found. (Code = 42) Position 1 = 213
Branch analysis from position: 213
Branch analysis from position: 146
2 jumps found. (Code = 43) Position 1 = 154, Position 2 = 160
Branch analysis from position: 154
1 jumps found. (Code = 42) Position 1 = 173
Branch analysis from position: 173
2 jumps found. (Code = 77) Position 1 = 182, Position 2 = 211
Branch analysis from position: 182
2 jumps found. (Code = 78) Position 1 = 183, Position 2 = 211
Branch analysis from position: 183
5 jumps found. (Code = 188) Position 1 = 191, Position 2 = 191, Position 3 = 192, Position 4 = 206, Position 5 = 184
Branch analysis from position: 191
1 jumps found. (Code = 42) Position 1 = 210
Branch analysis from position: 210
1 jumps found. (Code = 42) Position 1 = 182
Branch analysis from position: 182
Branch analysis from position: 191
Branch analysis from position: 192
1 jumps found. (Code = 42) Position 1 = 210
Branch analysis from position: 210
Branch analysis from position: 206
1 jumps found. (Code = 42) Position 1 = 210
Branch analysis from position: 210
Branch analysis from position: 184
2 jumps found. (Code = 44) Position 1 = 186, Position 2 = 191
Branch analysis from position: 186
2 jumps found. (Code = 44) Position 1 = 188, Position 2 = 191
Branch analysis from position: 188
2 jumps found. (Code = 44) Position 1 = 190, Position 2 = 192
Branch analysis from position: 190
1 jumps found. (Code = 42) Position 1 = 206
Branch analysis from position: 206
Branch analysis from position: 192
Branch analysis from position: 191
Branch analysis from position: 191
Branch analysis from position: 211
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 211
Branch analysis from position: 160
2 jumps found. (Code = 77) Position 1 = 182, Position 2 = 211
Branch analysis from position: 182
Branch analysis from position: 211
Branch analysis from position: 131
2 jumps found. (Code = 43) Position 1 = 137, Position 2 = 139
Branch analysis from position: 137
Branch analysis from position: 139
Branch analysis from position: 120
Branch analysis from position: 121
Branch analysis from position: 105
Branch analysis from position: 101
Branch analysis from position: 90
Branch analysis from position: 67
Branch analysis from position: 58
Branch analysis from position: 53
Branch analysis from position: 30
Branch analysis from position: 21
Branch analysis from position: 14
filename:       /in/BAeXW
function name:  make_absolute_path
number of ops:  215
compiled vars:  !0 = $a, !1 = $b, !2 = $c, !3 = $d, !4 = $e, !5 = $f, !6 = $g, !7 = $h
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    1     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        INIT_FCALL                                               'parse_url'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $8      
          5        ASSIGN                                           ~9      !2, $8
          6        BOOL_NOT                                         ~10     ~9
          7      > JMPNZ_EX                                         ~10     ~10, ->14
          8    >   INIT_FCALL                                               'parse_url'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $11     
         11        ASSIGN                                           ~12     !3, $11
         12        BOOL_NOT                                         ~13     ~12
         13        BOOL                                             ~10     ~13
         14    > > JMPZ                                                     ~10, ->16
         15    > > RETURN                                                   <false>
         16    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~14     !2, 'host'
         17      > JMPZ_EX                                          ~14     ~14, ->21
         18    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~15     !2, 'path'
         19        BOOL_NOT                                         ~16     ~15
         20        BOOL                                             ~14     ~16
         21    > > JMPZ_EX                                          ~14     ~14, ->30
         22    >   INIT_FCALL                                               'substr'
         23        FETCH_DIM_R                                      ~17     !2, 'path'
         24        SEND_VAL                                                 ~17
         25        SEND_VAL                                                 0
         26        SEND_VAL                                                 2
         27        DO_ICALL                                         $18     
         28        IS_IDENTICAL                                     ~19     $18, '%2F%2F'
         29        BOOL                                             ~14     ~19
         30    > > JMPZ                                                     ~14, ->53
         31    >   INIT_FCALL                                               'explode'
         32        SEND_VAL                                                 '%2F'
         33        INIT_FCALL                                               'ltrim'
         34        FETCH_DIM_R                                      ~20     !2, 'path'
         35        SEND_VAL                                                 ~20
         36        SEND_VAL                                                 '%2F'
         37        DO_ICALL                                         $21     
         38        SEND_VAR                                                 $21
         39        DO_ICALL                                         $22     
         40        ASSIGN                                                   !4, $22
         41        INIT_FCALL                                               'array_shift'
         42        SEND_REF                                                 !4
         43        DO_ICALL                                         $25     
         44        ASSIGN_DIM                                               !2, 'host'
         45        OP_DATA                                                  $25
         46        INIT_FCALL                                               'implode'
         47        SEND_VAL                                                 '%2F'
         48        SEND_VAR                                                 !4
         49        DO_ICALL                                         $27     
         50        CONCAT                                           ~28     '%2F', $27
         51        ASSIGN_DIM                                               !2, 'path'
         52        OP_DATA                                                  ~28
         53    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~29     !3, 'host'
         54      > JMPZ_EX                                          ~29     ~29, ->58
         55    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~30     !3, 'path'
         56        BOOL_NOT                                         ~31     ~30
         57        BOOL                                             ~29     ~31
         58    > > JMPZ_EX                                          ~29     ~29, ->67
         59    >   INIT_FCALL                                               'substr'
         60        FETCH_DIM_R                                      ~32     !3, 'path'
         61        SEND_VAL                                                 ~32
         62        SEND_VAL                                                 0
         63        SEND_VAL                                                 2
         64        DO_ICALL                                         $33     
         65        IS_IDENTICAL                                     ~34     $33, '%2F%2F'
         66        BOOL                                             ~29     ~34
         67    > > JMPZ                                                     ~29, ->90
         68    >   INIT_FCALL                                               'explode'
         69        SEND_VAL                                                 '%2F'
         70        INIT_FCALL                                               'ltrim'
         71        FETCH_DIM_R                                      ~35     !3, 'path'
         72        SEND_VAL                                                 ~35
         73        SEND_VAL                                                 '%2F'
         74        DO_ICALL                                         $36     
         75        SEND_VAR                                                 $36
         76        DO_ICALL                                         $37     
         77        ASSIGN                                                   !4, $37
         78        INIT_FCALL                                               'array_shift'
         79        SEND_REF                                                 !4
         80        DO_ICALL                                         $40     
         81        ASSIGN_DIM                                               !3, 'host'
         82        OP_DATA                                                  $40
         83        INIT_FCALL                                               'implode'
         84        SEND_VAL                                                 '%2F'
         85        SEND_VAR                                                 !4
         86        DO_ICALL                                         $42     
         87        CONCAT                                           ~43     '%2F', $42
         88        ASSIGN_DIM                                               !3, 'path'
         89        OP_DATA                                                  ~43
         90    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~44     !3, 'host'
         91        BOOL_NOT                                         ~45     ~44
         92      > JMPZ                                                     ~45, ->94
         93    > > RETURN                                                   !1
         94    >   ISSET_ISEMPTY_DIM_OBJ                         1          !2, 'host'
         95      > JMPZ                                                     ~46, ->97
         96    > > RETURN                                                   <false>
         97    >   ISSET_ISEMPTY_DIM_OBJ                         1          !2, 'path'
         98      > JMPZ                                                     ~47, ->101
         99    >   ASSIGN_DIM                                               !2, 'path'
        100        OP_DATA                                                  '%2F'
        101    >   ISSET_ISEMPTY_DIM_OBJ                         1          !2, 'scheme'
        102      > JMPZ                                                     ~49, ->105
        103    >   ASSIGN_DIM                                               !2, 'scheme'
        104        OP_DATA                                                  'http'
        105    >   FETCH_DIM_R                                      ~51     !2, 'scheme'
        106        CONCAT                                           ~52     ~51, '%3A%2F%2F'
        107        ASSIGN                                                   !5, ~52
        108        ISSET_ISEMPTY_DIM_OBJ                         1  ~54     !2, 'user'
        109        BOOL_NOT                                         ~55     ~54
        110      > JMPZ                                                     ~55, ->121
        111    >   FETCH_DIM_R                                      ~56     !2, 'user'
        112        ASSIGN_OP                                     8          !5, ~56
        113        ISSET_ISEMPTY_DIM_OBJ                         1  ~58     !2, 'pass'
        114        BOOL_NOT                                         ~59     ~58
        115      > JMPZ                                                     ~59, ->120
        116    >   NOP                                                      
        117        FETCH_DIM_R                                      ~60     !2, 'pass'
        118        FAST_CONCAT                                      ~61     '%3A', ~60
        119        ASSIGN_OP                                     8          !5, ~61
        120    >   ASSIGN_OP                                     8          !5, '%40'
        121    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~64     !2, 'port'
        122        BOOL_NOT                                         ~65     ~64
        123      > JMPZ                                                     ~65, ->131
        124    >   FETCH_DIM_R                                      ~66     !2, 'host'
        125        ROPE_INIT                                     3  ~69     ~66
        126        ROPE_ADD                                      1  ~69     ~69, '%3A'
        127        FETCH_DIM_R                                      ~67     !2, 'port'
        128        ROPE_END                                      2  ~68     ~69, ~67
        129        QM_ASSIGN                                        ~71     ~68
        130      > JMP                                                      ->133
        131    >   FETCH_DIM_R                                      ~72     !2, 'host'
        132        QM_ASSIGN                                        ~71     ~72
        133    >   ASSIGN_OP                                     8          !5, ~71
        134        FETCH_DIM_R                                      ~74     !1, 0
        135        IS_IDENTICAL                                             ~74, '%2F'
        136      > JMPZ                                                     ~75, ->139
        137    >   ASSIGN_OP                                     8          !5, !1
        138      > JMP                                                      ->213
        139    >   FETCH_DIM_R                                      ~77     !1, 0
        140        IS_IDENTICAL                                             ~77, '%3F'
        141      > JMPZ                                                     ~78, ->146
        142    >   FETCH_DIM_R                                      ~79     !2, 'path'
        143        CONCAT                                           ~80     ~79, !1
        144        ASSIGN_OP                                     8          !5, ~80
        145      > JMP                                                      ->213
        146    >   INIT_FCALL                                               'rtrim'
        147        INIT_FCALL                                               'substr'
        148        FETCH_DIM_R                                      ~82     !2, 'path'
        149        SEND_VAL                                                 ~82
        150        SEND_VAL                                                 -1
        151        DO_ICALL                                         $83     
        152        IS_IDENTICAL                                             $83, '%2F'
        153      > JMPZ                                                     ~84, ->160
        154    >   INIT_FCALL                                               'trim'
        155        FETCH_DIM_R                                      ~85     !2, 'path'
        156        SEND_VAL                                                 ~85
        157        DO_ICALL                                         $86     
        158        QM_ASSIGN                                        ~87     $86
        159      > JMP                                                      ->173
        160    >   INIT_FCALL                                               'str_replace'
        161        SEND_VAL                                                 '%5C'
        162        SEND_VAL                                                 '%2F'
        163        INIT_FCALL                                               'dirname'
        164        INIT_FCALL                                               'trim'
        165        FETCH_DIM_R                                      ~88     !2, 'path'
        166        SEND_VAL                                                 ~88
        167        DO_ICALL                                         $89     
        168        SEND_VAR                                                 $89
        169        DO_ICALL                                         $90     
        170        SEND_VAR                                                 $90
        171        DO_ICALL                                         $91     
        172        QM_ASSIGN                                        ~87     $91
        173    >   SEND_VAL                                                 ~87
        174        SEND_VAL                                                 '%2F'
        175        DO_ICALL                                         $92     
        176        ASSIGN                                                   !6, $92
        177        INIT_FCALL                                               'explode'
        178        SEND_VAL                                                 '%2F'
        179        SEND_VAR                                                 !1
        180        DO_ICALL                                         $94     
        181      > FE_RESET_R                                       $95     $94, ->211
        182    > > FE_FETCH_R                                               $95, !7, ->211
        183    > > SWITCH_STRING                                            !7, [ '':->191, '.':->191, '..':->192, ], ->206
        184    >   IS_EQUAL                                                 !7, ''
        185      > JMPNZ                                                    ~96, ->191
        186    >   IS_EQUAL                                                 !7, '.'
        187      > JMPNZ                                                    ~96, ->191
        188    >   IS_EQUAL                                                 !7, '..'
        189      > JMPNZ                                                    ~96, ->192
        190    > > JMP                                                      ->206
        191    > > JMP                                                      ->210
        192    >   INIT_FCALL                                               'rtrim'
        193        INIT_FCALL                                               'str_replace'
        194        SEND_VAL                                                 '%5C'
        195        SEND_VAL                                                 '%2F'
        196        INIT_FCALL                                               'dirname'
        197        SEND_VAR                                                 !6
        198        DO_ICALL                                         $97     
        199        SEND_VAR                                                 $97
        200        DO_ICALL                                         $98     
        201        SEND_VAR                                                 $98
        202        SEND_VAL                                                 '%2F'
        203        DO_ICALL                                         $99     
        204        ASSIGN                                                   !6, $99
        205      > JMP                                                      ->210
        206    >   NOP                                                      
        207        FAST_CONCAT                                      ~101    '%2F', !7
        208        ASSIGN_OP                                     8          !6, ~101
        209      > JMP                                                      ->210
        210    > > JMP                                                      ->182
        211    >   FE_FREE                                                  $95
        212        ASSIGN_OP                                     8          !5, !6
        213    > > RETURN                                                   !5
        214*     > RETURN                                                   null

End of function make_absolute_path

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.66 ms | 1423 KiB | 34 Q