3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getBaseURLPath() { return 'https://example.com/sub-directory/'; } function getBaseURLPathOnly() { return '/'; } function buildWithBaseURLPathOld($info, $baseURLPath) { $result = ''; if (!empty($baseURLPath)) { $result = $baseURLPath; if (!empty($info)) { $path = explode('/', $info); // Remove base path from the path info. $extractedInfo = array_pop($path); if (!empty($extractedInfo)) { $result .= $extractedInfo; } } } return $result; } function buildWithBaseURLPathNew($info, $baseURLPath) { $result = ''; if (!empty($baseURLPath)) { $result = $baseURLPath; if (!empty($info)) { // Remove base path from the path info. $extractedInfo = str_replace($baseURLPath, '', $info); // Remove starting and ending slash. $extractedInfo = trim($extractedInfo, '/'); if (!empty($extractedInfo)) { $result .= $extractedInfo; } } } return $result; } echo "Old: " . buildWithBaseURLPathOld('saml/acs',getBaseURLPath()) . PHP_EOL; echo "New: " . buildWithBaseURLPathNew('saml/acs',getBaseURLPath()) . PHP_EOL; echo "Old: " . buildWithBaseURLPathOld('/saml/acs',getBaseURLPath()) . PHP_EOL; echo "New: " . buildWithBaseURLPathNew('/saml/acs',getBaseURLPath()) . PHP_EOL; echo "Old: " . buildWithBaseURLPathOld('/',getBaseURLPath()) . PHP_EOL; echo "New: " . buildWithBaseURLPathNew('/',getBaseURLPath()) . PHP_EOL; echo "Old: " . buildWithBaseURLPathOld('',getBaseURLPath()) . PHP_EOL; echo "New: " . buildWithBaseURLPathNew('',getBaseURLPath()) . PHP_EOL; // Case not considered where URL is not a URL... echo "Old: " . buildWithBaseURLPathOld('saml/acs',getBaseURLPathOnly()) . PHP_EOL; echo "New: " . buildWithBaseURLPathNew('saml/acs',getBaseURLPathOnly()) . PHP_EOL; echo "Old: " . buildWithBaseURLPathOld('/saml/acs',getBaseURLPathOnly()) . PHP_EOL; echo "New: " . buildWithBaseURLPathNew('/saml/acs',getBaseURLPathOnly()) . PHP_EOL; echo "Old: " . buildWithBaseURLPathOld('/',getBaseURLPathOnly()) . PHP_EOL; echo "New: " . buildWithBaseURLPathNew('/',getBaseURLPathOnly()) . PHP_EOL; echo "Old: " . buildWithBaseURLPathOld('',getBaseURLPathOnly()) . PHP_EOL; echo "New: " . buildWithBaseURLPathNew('',getBaseURLPathOnly()) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/p86qT
function name:  (null)
number of ops:  145
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   INIT_FCALL                                               'buildwithbaseurlpathold'
          1        SEND_VAL                                                 'saml%2Facs'
          2        INIT_FCALL                                               'getbaseurlpath'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_FCALL                                      0  $1      
          6        CONCAT                                           ~2      'Old%3A+', $1
          7        CONCAT                                           ~3      ~2, '%0A'
          8        ECHO                                                     ~3
   43     9        INIT_FCALL                                               'buildwithbaseurlpathnew'
         10        SEND_VAL                                                 'saml%2Facs'
         11        INIT_FCALL                                               'getbaseurlpath'
         12        DO_FCALL                                      0  $4      
         13        SEND_VAR                                                 $4
         14        DO_FCALL                                      0  $5      
         15        CONCAT                                           ~6      'New%3A+', $5
         16        CONCAT                                           ~7      ~6, '%0A'
         17        ECHO                                                     ~7
   44    18        INIT_FCALL                                               'buildwithbaseurlpathold'
         19        SEND_VAL                                                 '%2Fsaml%2Facs'
         20        INIT_FCALL                                               'getbaseurlpath'
         21        DO_FCALL                                      0  $8      
         22        SEND_VAR                                                 $8
         23        DO_FCALL                                      0  $9      
         24        CONCAT                                           ~10     'Old%3A+', $9
         25        CONCAT                                           ~11     ~10, '%0A'
         26        ECHO                                                     ~11
   45    27        INIT_FCALL                                               'buildwithbaseurlpathnew'
         28        SEND_VAL                                                 '%2Fsaml%2Facs'
         29        INIT_FCALL                                               'getbaseurlpath'
         30        DO_FCALL                                      0  $12     
         31        SEND_VAR                                                 $12
         32        DO_FCALL                                      0  $13     
         33        CONCAT                                           ~14     'New%3A+', $13
         34        CONCAT                                           ~15     ~14, '%0A'
         35        ECHO                                                     ~15
   46    36        INIT_FCALL                                               'buildwithbaseurlpathold'
         37        SEND_VAL                                                 '%2F'
         38        INIT_FCALL                                               'getbaseurlpath'
         39        DO_FCALL                                      0  $16     
         40        SEND_VAR                                                 $16
         41        DO_FCALL                                      0  $17     
         42        CONCAT                                           ~18     'Old%3A+', $17
         43        CONCAT                                           ~19     ~18, '%0A'
         44        ECHO                                                     ~19
   47    45        INIT_FCALL                                               'buildwithbaseurlpathnew'
         46        SEND_VAL                                                 '%2F'
         47        INIT_FCALL                                               'getbaseurlpath'
         48        DO_FCALL                                      0  $20     
         49        SEND_VAR                                                 $20
         50        DO_FCALL                                      0  $21     
         51        CONCAT                                           ~22     'New%3A+', $21
         52        CONCAT                                           ~23     ~22, '%0A'
         53        ECHO                                                     ~23
   48    54        INIT_FCALL                                               'buildwithbaseurlpathold'
         55        SEND_VAL                                                 ''
         56        INIT_FCALL                                               'getbaseurlpath'
         57        DO_FCALL                                      0  $24     
         58        SEND_VAR                                                 $24
         59        DO_FCALL                                      0  $25     
         60        CONCAT                                           ~26     'Old%3A+', $25
         61        CONCAT                                           ~27     ~26, '%0A'
         62        ECHO                                                     ~27
   49    63        INIT_FCALL                                               'buildwithbaseurlpathnew'
         64        SEND_VAL                                                 ''
         65        INIT_FCALL                                               'getbaseurlpath'
         66        DO_FCALL                                      0  $28     
         67        SEND_VAR                                                 $28
         68        DO_FCALL                                      0  $29     
         69        CONCAT                                           ~30     'New%3A+', $29
         70        CONCAT                                           ~31     ~30, '%0A'
         71        ECHO                                                     ~31
   52    72        INIT_FCALL                                               'buildwithbaseurlpathold'
         73        SEND_VAL                                                 'saml%2Facs'
         74        INIT_FCALL                                               'getbaseurlpathonly'
         75        DO_FCALL                                      0  $32     
         76        SEND_VAR                                                 $32
         77        DO_FCALL                                      0  $33     
         78        CONCAT                                           ~34     'Old%3A+', $33
         79        CONCAT                                           ~35     ~34, '%0A'
         80        ECHO                                                     ~35
   53    81        INIT_FCALL                                               'buildwithbaseurlpathnew'
         82        SEND_VAL                                                 'saml%2Facs'
         83        INIT_FCALL                                               'getbaseurlpathonly'
         84        DO_FCALL                                      0  $36     
         85        SEND_VAR                                                 $36
         86        DO_FCALL                                      0  $37     
         87        CONCAT                                           ~38     'New%3A+', $37
         88        CONCAT                                           ~39     ~38, '%0A'
         89        ECHO                                                     ~39
   54    90        INIT_FCALL                                               'buildwithbaseurlpathold'
         91        SEND_VAL                                                 '%2Fsaml%2Facs'
         92        INIT_FCALL                                               'getbaseurlpathonly'
         93        DO_FCALL                                      0  $40     
         94        SEND_VAR                                                 $40
         95        DO_FCALL                                      0  $41     
         96        CONCAT                                           ~42     'Old%3A+', $41
         97        CONCAT                                           ~43     ~42, '%0A'
         98        ECHO                                                     ~43
   55    99        INIT_FCALL                                               'buildwithbaseurlpathnew'
        100        SEND_VAL                                                 '%2Fsaml%2Facs'
        101        INIT_FCALL                                               'getbaseurlpathonly'
        102        DO_FCALL                                      0  $44     
        103        SEND_VAR                                                 $44
        104        DO_FCALL                                      0  $45     
        105        CONCAT                                           ~46     'New%3A+', $45
        106        CONCAT                                           ~47     ~46, '%0A'
        107        ECHO                                                     ~47
   56   108        INIT_FCALL                                               'buildwithbaseurlpathold'
        109        SEND_VAL                                                 '%2F'
        110        INIT_FCALL                                               'getbaseurlpathonly'
        111        DO_FCALL                                      0  $48     
        112        SEND_VAR                                                 $48
        113        DO_FCALL                                      0  $49     
        114        CONCAT                                           ~50     'Old%3A+', $49
        115        CONCAT                                           ~51     ~50, '%0A'
        116        ECHO                                                     ~51
   57   117        INIT_FCALL                                               'buildwithbaseurlpathnew'
        118        SEND_VAL                                                 '%2F'
        119        INIT_FCALL                                               'getbaseurlpathonly'
        120        DO_FCALL                                      0  $52     
        121        SEND_VAR                                                 $52
        122        DO_FCALL                                      0  $53     
        123        CONCAT                                           ~54     'New%3A+', $53
        124        CONCAT                                           ~55     ~54, '%0A'
        125        ECHO                                                     ~55
   58   126        INIT_FCALL                                               'buildwithbaseurlpathold'
        127        SEND_VAL                                                 ''
        128        INIT_FCALL                                               'getbaseurlpathonly'
        129        DO_FCALL                                      0  $56     
        130        SEND_VAR                                                 $56
        131        DO_FCALL                                      0  $57     
        132        CONCAT                                           ~58     'Old%3A+', $57
        133        CONCAT                                           ~59     ~58, '%0A'
        134        ECHO                                                     ~59
   59   135        INIT_FCALL                                               'buildwithbaseurlpathnew'
        136        SEND_VAL                                                 ''
        137        INIT_FCALL                                               'getbaseurlpathonly'
        138        DO_FCALL                                      0  $60     
        139        SEND_VAR                                                 $60
        140        DO_FCALL                                      0  $61     
        141        CONCAT                                           ~62     'New%3A+', $61
        142        CONCAT                                           ~63     ~62, '%0A'
        143        ECHO                                                     ~63
   60   144      > RETURN                                                   1

Function getbaseurlpath:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/p86qT
function name:  getBaseURLPath
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E > > RETURN                                                   'https%3A%2F%2Fexample.com%2Fsub-directory%2F'
    4     1*     > RETURN                                                   null

End of function getbaseurlpath

Function getbaseurlpathonly:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/p86qT
function name:  getBaseURLPathOnly
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E > > RETURN                                                   '%2F'
    7     1*     > RETURN                                                   null

End of function getbaseurlpathonly

Function buildwithbaseurlpathold:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 23
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 23
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
Branch analysis from position: 23
Branch analysis from position: 23
filename:       /in/p86qT
function name:  buildWithBaseURLPathOld
number of ops:  25
compiled vars:  !0 = $info, !1 = $baseURLPath, !2 = $result, !3 = $path, !4 = $extractedInfo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        ASSIGN                                                   !2, ''
   11     3        ISSET_ISEMPTY_CV                                 ~6      !1
          4        BOOL_NOT                                         ~7      ~6
          5      > JMPZ                                                     ~7, ->23
   12     6    >   ASSIGN                                                   !2, !1
   13     7        ISSET_ISEMPTY_CV                                 ~9      !0
          8        BOOL_NOT                                         ~10     ~9
          9      > JMPZ                                                     ~10, ->23
   14    10    >   INIT_FCALL                                               'explode'
         11        SEND_VAL                                                 '%2F'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $11     
         14        ASSIGN                                                   !3, $11
   16    15        INIT_FCALL                                               'array_pop'
         16        SEND_REF                                                 !3
         17        DO_ICALL                                         $13     
         18        ASSIGN                                                   !4, $13
   17    19        ISSET_ISEMPTY_CV                                 ~15     !4
         20        BOOL_NOT                                         ~16     ~15
         21      > JMPZ                                                     ~16, ->23
   18    22    >   ASSIGN_OP                                     8          !2, !4
   22    23    > > RETURN                                                   !2
   23    24*     > RETURN                                                   null

End of function buildwithbaseurlpathold

Function buildwithbaseurlpathnew:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 25
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 25
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 25
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
Branch analysis from position: 25
Branch analysis from position: 25
filename:       /in/p86qT
function name:  buildWithBaseURLPathNew
number of ops:  27
compiled vars:  !0 = $info, !1 = $baseURLPath, !2 = $result, !3 = $extractedInfo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   27     2        ASSIGN                                                   !2, ''
   28     3        ISSET_ISEMPTY_CV                                 ~5      !1
          4        BOOL_NOT                                         ~6      ~5
          5      > JMPZ                                                     ~6, ->25
   29     6    >   ASSIGN                                                   !2, !1
   30     7        ISSET_ISEMPTY_CV                                 ~8      !0
          8        BOOL_NOT                                         ~9      ~8
          9      > JMPZ                                                     ~9, ->25
   32    10    >   INIT_FCALL                                               'str_replace'
         11        SEND_VAR                                                 !1
         12        SEND_VAL                                                 ''
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $10     
         15        ASSIGN                                                   !3, $10
   34    16        INIT_FCALL                                               'trim'
         17        SEND_VAR                                                 !3
         18        SEND_VAL                                                 '%2F'
         19        DO_ICALL                                         $12     
         20        ASSIGN                                                   !3, $12
   35    21        ISSET_ISEMPTY_CV                                 ~14     !3
         22        BOOL_NOT                                         ~15     ~14
         23      > JMPZ                                                     ~15, ->25
   36    24    >   ASSIGN_OP                                     8          !2, !3
   40    25    > > RETURN                                                   !2
   41    26*     > RETURN                                                   null

End of function buildwithbaseurlpathnew

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.76 ms | 1455 KiB | 49 Q