3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test($DIRECTORY_SEPARATOR, $source, $path, $expected) { $folder = str_replace(rtrim($source, $DIRECTORY_SEPARATOR), '', dirname($path)); echo "Expected: $expected\n"; echo "Actual: $folder\n"; echo "--------------\n"; } test('/', '/site/path', '/site/path/backed/up/item.txt', '/backed/up'); test('/', '/site/path/', '/site/path/backed/up/item.txt', '/backed/up'); test('\\', 'C:\\site\\path', 'C:/site/path/backed/up/item.txt', '/backed/up'); test('\\', 'C:\\site\\path\\', 'C:/site/path/backed/up/item.txt', '/backed/up'); test('\\', 'C:/site/path', 'C:/site/path/backed/up/item.txt', '/backed/up'); test('\\', 'C:/site/path/', 'C:/site/path/backed/up/item.txt', '/backed/up');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/q8jmd
function name:  (null)
number of ops:  37
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   INIT_FCALL                                               'test'
          1        SEND_VAL                                                 '%2F'
          2        SEND_VAL                                                 '%2Fsite%2Fpath'
          3        SEND_VAL                                                 '%2Fsite%2Fpath%2Fbacked%2Fup%2Fitem.txt'
          4        SEND_VAL                                                 '%2Fbacked%2Fup'
          5        DO_FCALL                                      0          
   12     6        INIT_FCALL                                               'test'
          7        SEND_VAL                                                 '%2F'
          8        SEND_VAL                                                 '%2Fsite%2Fpath%2F'
          9        SEND_VAL                                                 '%2Fsite%2Fpath%2Fbacked%2Fup%2Fitem.txt'
         10        SEND_VAL                                                 '%2Fbacked%2Fup'
         11        DO_FCALL                                      0          
   13    12        INIT_FCALL                                               'test'
         13        SEND_VAL                                                 '%5C'
         14        SEND_VAL                                                 'C%3A%5Csite%5Cpath'
         15        SEND_VAL                                                 'C%3A%2Fsite%2Fpath%2Fbacked%2Fup%2Fitem.txt'
         16        SEND_VAL                                                 '%2Fbacked%2Fup'
         17        DO_FCALL                                      0          
   14    18        INIT_FCALL                                               'test'
         19        SEND_VAL                                                 '%5C'
         20        SEND_VAL                                                 'C%3A%5Csite%5Cpath%5C'
         21        SEND_VAL                                                 'C%3A%2Fsite%2Fpath%2Fbacked%2Fup%2Fitem.txt'
         22        SEND_VAL                                                 '%2Fbacked%2Fup'
         23        DO_FCALL                                      0          
   15    24        INIT_FCALL                                               'test'
         25        SEND_VAL                                                 '%5C'
         26        SEND_VAL                                                 'C%3A%2Fsite%2Fpath'
         27        SEND_VAL                                                 'C%3A%2Fsite%2Fpath%2Fbacked%2Fup%2Fitem.txt'
         28        SEND_VAL                                                 '%2Fbacked%2Fup'
         29        DO_FCALL                                      0          
   16    30        INIT_FCALL                                               'test'
         31        SEND_VAL                                                 '%5C'
         32        SEND_VAL                                                 'C%3A%2Fsite%2Fpath%2F'
         33        SEND_VAL                                                 'C%3A%2Fsite%2Fpath%2Fbacked%2Fup%2Fitem.txt'
         34        SEND_VAL                                                 '%2Fbacked%2Fup'
         35        DO_FCALL                                      0          
         36      > RETURN                                                   1

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/q8jmd
function name:  test
number of ops:  27
compiled vars:  !0 = $DIRECTORY_SEPARATOR, !1 = $source, !2 = $path, !3 = $expected, !4 = $folder
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
    4     4        INIT_FCALL                                               'str_replace'
          5        INIT_FCALL                                               'rtrim'
          6        SEND_VAR                                                 !1
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $5      
          9        SEND_VAR                                                 $5
         10        SEND_VAL                                                 ''
         11        INIT_FCALL                                               'dirname'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $6      
         14        SEND_VAR                                                 $6
         15        DO_ICALL                                         $7      
         16        ASSIGN                                                   !4, $7
    6    17        ROPE_INIT                                     3  ~10     'Expected%3A+'
         18        ROPE_ADD                                      1  ~10     ~10, !3
         19        ROPE_END                                      2  ~9      ~10, '%0A'
         20        ECHO                                                     ~9
    7    21        ROPE_INIT                                     3  ~13     'Actual%3A+++'
         22        ROPE_ADD                                      1  ~13     ~13, !4
         23        ROPE_END                                      2  ~12     ~13, '%0A'
         24        ECHO                                                     ~12
    8    25        ECHO                                                     '--------------%0A'
    9    26      > RETURN                                                   null

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
199.87 ms | 1403 KiB | 25 Q