3v4l.org

run code in 500+ PHP versions simultaneously
<?php $allowed_ext = array ( 'bmp', 'jpg', 'jpeg', 'gif', 'pdf' ); $arr = array( 1 => 'file-to-path/thumbs/allowedfile.pdf', 2 => 'file-to-path/thumbs/notallowedfile.psd', 3 => 'file-to-path/project/test/notallowedfile.txt' ); $errors = []; foreach ($arr as $key => $value) { if (!in_array(pathinfo($value, PATHINFO_EXTENSION), $allowed_ext)) { $errors[] = basename($value).' is not allowed.'; unset($arr[$key]); } } print_r($errors); print_r($arr);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 21
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 21
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 20
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 20
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/oSOJT
function name:  (null)
number of ops:  29
compiled vars:  !0 = $allowed_ext, !1 = $arr, !2 = $errors, !3 = $value, !4 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
   10     1        ASSIGN                                                       !1, <array>
   16     2        ASSIGN                                                       !2, <array>
   18     3      > FE_RESET_R                                           $8      !1, ->21
          4    > > FE_FETCH_R                                           ~9      $8, !3, ->21
          5    >   ASSIGN                                                       !4, ~9
   19     6        INIT_FCALL                                                   'pathinfo'
          7        SEND_VAR                                                     !3
          8        SEND_VAL                                                     4
          9        DO_ICALL                                             $11     
         10        FRAMELESS_ICALL_2                in_array            ~12     $11, !0
         11        BOOL_NOT                                             ~13     ~12
         12      > JMPZ                                                         ~13, ->20
   20    13    >   INIT_FCALL                                                   'basename'
         14        SEND_VAR                                                     !3
         15        DO_ICALL                                             $15     
         16        CONCAT                                               ~16     $15, '+is+not+allowed.'
         17        ASSIGN_DIM                                                   !2
         18        OP_DATA                                                      ~16
   21    19        UNSET_DIM                                                    !1, !4
   18    20    > > JMP                                                          ->4
         21    >   FE_FREE                                                      $8
   25    22        INIT_FCALL                                                   'print_r'
         23        SEND_VAR                                                     !2
         24        DO_ICALL                                                     
   27    25        INIT_FCALL                                                   'print_r'
         26        SEND_VAR                                                     !1
         27        DO_ICALL                                                     
   29    28      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
162.01 ms | 2031 KiB | 16 Q