3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getExt($filename) { if(!is_file($filename)) return ''; $n = strlen($filename); if($n<2) return ''; $non_ext = ''; $ext = ''; Echo $filename; 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/0qdGm
function name:  (null)
number of ops:  9
compiled vars:  !0 = $filename, !1 = $ext
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, 'asdfasdfasd.tar.gz'
   22     1        INIT_FCALL                                               'getext'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   23     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 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
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/0qdGm
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      
    5     1        INIT_FCALL                                               'is_file'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $6      
          4        BOOL_NOT                                         ~7      $6
          5      > JMPZ                                                     ~7, ->7
          6    > > RETURN                                                   ''
    6     7    >   STRLEN                                           ~8      !0
          8        ASSIGN                                                   !1, ~8
    7     9        IS_SMALLER                                               !1, 2
         10      > JMPZ                                                     ~10, ->12
         11    > > RETURN                                                   ''
    8    12    >   ASSIGN                                                   !2, ''
    9    13        ASSIGN                                                   !3, ''
   10    14        ECHO                                                     !0
   11    15        ASSIGN                                                   !4, !1
         16      > JMP                                                      ->30
   12    17    >   FETCH_DIM_R                                      ~14     !0, !4
         18        ASSIGN                                                   !5, ~14
   13    19        IS_IDENTICAL                                             !5, '.'
         20      > JMPZ                                                     ~16, ->26
   14    21    >   CONCAT                                           ~17     '.', !2
         22        CONCAT                                           ~18     ~17, !3
         23        ASSIGN                                                   !3, ~18
   15    24        ASSIGN                                                   !2, ''
         25      > JMP                                                      ->28
   17    26    >   CONCAT                                           ~21     !5, !2
         27        ASSIGN                                                   !2, ~21
   11    28    >   IS_SMALLER_OR_EQUAL                              ~23     1, !4
         29        FREE                                                     ~23
         30    >   POST_DEC                                         ~24     !4
         31      > JMPNZ                                                    ~24, ->17
   19    32    > > RETURN                                                   !3
   20    33*     > RETURN                                                   null

End of function getext

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.66 ms | 1403 KiB | 18 Q