3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getExt($filename) { Echo $filename; if(!is_file($filename)) return ''; $n = strlen($filename); if($n<2) return ''; $non_ext = ''; $ext = ''; for($i=$n;$i--;$i>=1) { $c = $filename[$i]; if($c==='.') { $ext = '.'.$non_ext.$ext; $non_ext = ''; }else $non_ext = $c.$non_ext; } return $ext; } $filename = "asdfasdfasd.tar.gz"; $ext = getExt($filename); var_dump($ext);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2N3X2
function name:  (null)
number of ops:  9
compiled vars:  !0 = $filename, !1 = $ext
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   ASSIGN                                                   !0, 'asdfasdfasd.tar.gz'
   21     1        INIT_FCALL                                               'getext'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   22     5        INIT_FCALL                                               'var_dump'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function getext:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 17
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 17
Branch analysis from position: 32
Branch analysis from position: 17
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 17
Branch analysis from position: 32
Branch analysis from position: 17
filename:       /in/2N3X2
function name:  getExt
number of ops:  34
compiled vars:  !0 = $filename, !1 = $n, !2 = $non_ext, !3 = $ext, !4 = $i, !5 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ECHO                                                     !0
    5     2        INIT_FCALL                                               'is_file'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $6      
          5        BOOL_NOT                                         ~7      $6
          6      > JMPZ                                                     ~7, ->8
          7    > > RETURN                                                   ''
    6     8    >   STRLEN                                           ~8      !0
          9        ASSIGN                                                   !1, ~8
    7    10        IS_SMALLER                                               !1, 2
         11      > JMPZ                                                     ~10, ->13
         12    > > RETURN                                                   ''
    8    13    >   ASSIGN                                                   !2, ''
    9    14        ASSIGN                                                   !3, ''
   10    15        ASSIGN                                                   !4, !1
         16      > JMP                                                      ->30
   11    17    >   FETCH_DIM_R                                      ~14     !0, !4
         18        ASSIGN                                                   !5, ~14
   12    19        IS_IDENTICAL                                             !5, '.'
         20      > JMPZ                                                     ~16, ->26
   13    21    >   CONCAT                                           ~17     '.', !2
         22        CONCAT                                           ~18     ~17, !3
         23        ASSIGN                                                   !3, ~18
   14    24        ASSIGN                                                   !2, ''
         25      > JMP                                                      ->28
   16    26    >   CONCAT                                           ~21     !5, !2
         27        ASSIGN                                                   !2, ~21
   10    28    >   IS_SMALLER_OR_EQUAL                              ~23     1, !4
         29        FREE                                                     ~23
         30    >   POST_DEC                                         ~24     !4
         31      > JMPNZ                                                    ~24, ->17
   18    32    > > RETURN                                                   !3
   19    33*     > RETURN                                                   null

End of function getext

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.86 ms | 1403 KiB | 18 Q