3v4l.org

run code in 500+ PHP versions simultaneously
<?php $data1 = '"slug,1", slug 2, test, "slug, 3", " ", "", ",",'; $data2 = 'foo, bar'; $data3 = 'foo, bar, "'; function is_valid_plugin_slug($slug) { return trim($slug, ", \t\n\r\0\x0B") !== ''; } function str_getcsv_augmented($data) { $plugins = str_getcsv( str_replace('""', '', $data ) ); return array_filter($plugins, 'is_valid_plugin_slug'); } function extract_required_plugins_from_header($required) { if (!$required || (substr_count($required, '"') < 2)) { return $required ? array_filter(array_map('trim', explode(',', str_replace('"', '', $required)))) : []; } $required = str_replace('""', '', $required); preg_match_all('#"([^"]+)"#', $required, $matches); $slugs = array_filter(array_map('trim', explode(',', strtr($required, array_fill_keys($matches[0], ''))))); return array_merge(array_filter($matches[1], 'is_valid_plugin_slug'), $slugs); } echo "Bare str_getcsv:\n"; var_dump( str_getcsv( $data1 ), str_getcsv( $data2 ), str_getcsv( $data3 ) ); echo "\n\nstr_getcsv with filtering:\n"; var_dump( str_getcsv_augmented( $data1 ), str_getcsv_augmented( $data2 ), str_getcsv_augmented( $data3 ) ); echo "\n\nextract_required_plugins_from_header:\n"; var_dump( extract_required_plugins_from_header( $data1 ), extract_required_plugins_from_header( $data2 ), extract_required_plugins_from_header( $data3 ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Uudsc
function name:  (null)
number of ops:  49
compiled vars:  !0 = $data1, !1 = $data2, !2 = $data3
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%22slug%2C1%22%2C+slug+2%2C+test%2C+%22slug%2C+3%22%2C+%22+%22%2C+%22%22%2C+%22%2C%22%2C'
    4     1        ASSIGN                                                       !1, 'foo%2C+++bar'
    5     2        ASSIGN                                                       !2, 'foo%2C+bar%2C+%22'
   35     3        ECHO                                                         'Bare+str_getcsv%3A%0A'
   36     4        INIT_FCALL                                                   'var_dump'
   37     5        INIT_FCALL                                                   'str_getcsv'
          6        SEND_VAR                                                     !0
          7        DO_ICALL                                             $6      
          8        SEND_VAR                                                     $6
   38     9        INIT_FCALL                                                   'str_getcsv'
         10        SEND_VAR                                                     !1
         11        DO_ICALL                                             $7      
         12        SEND_VAR                                                     $7
   39    13        INIT_FCALL                                                   'str_getcsv'
         14        SEND_VAR                                                     !2
         15        DO_ICALL                                             $8      
         16        SEND_VAR                                                     $8
   36    17        DO_ICALL                                                     
   42    18        ECHO                                                         '%0A%0Astr_getcsv+with+filtering%3A%0A'
   43    19        INIT_FCALL                                                   'var_dump'
   44    20        INIT_FCALL                                                   'str_getcsv_augmented'
         21        SEND_VAR                                                     !0
         22        DO_FCALL                                          0  $10     
         23        SEND_VAR                                                     $10
   45    24        INIT_FCALL                                                   'str_getcsv_augmented'
         25        SEND_VAR                                                     !1
         26        DO_FCALL                                          0  $11     
         27        SEND_VAR                                                     $11
   46    28        INIT_FCALL                                                   'str_getcsv_augmented'
         29        SEND_VAR                                                     !2
         30        DO_FCALL                                          0  $12     
         31        SEND_VAR                                                     $12
   43    32        DO_ICALL                                                     
   49    33        ECHO                                                         '%0A%0Aextract_required_plugins_from_header%3A%0A'
   50    34        INIT_FCALL                                                   'var_dump'
   51    35        INIT_FCALL                                                   'extract_required_plugins_from_header'
         36        SEND_VAR                                                     !0
         37        DO_FCALL                                          0  $14     
         38        SEND_VAR                                                     $14
   52    39        INIT_FCALL                                                   'extract_required_plugins_from_header'
         40        SEND_VAR                                                     !1
         41        DO_FCALL                                          0  $15     
         42        SEND_VAR                                                     $15
   53    43        INIT_FCALL                                                   'extract_required_plugins_from_header'
         44        SEND_VAR                                                     !2
         45        DO_FCALL                                          0  $16     
         46        SEND_VAR                                                     $16
   50    47        DO_ICALL                                                     
   54    48      > RETURN                                                       1

Function is_valid_plugin_slug:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Uudsc
function name:  is_valid_plugin_slug
number of ops:  5
compiled vars:  !0 = $slug
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
    9     1        FRAMELESS_ICALL_2                trim                ~1      !0, '%2C+%09%0A%0D%00%0B'
          2        IS_NOT_IDENTICAL                                     ~2      ~1, ''
          3      > RETURN                                                       ~2
   10     4*     > RETURN                                                       null

End of function is_valid_plugin_slug

Function str_getcsv_augmented:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Uudsc
function name:  str_getcsv_augmented
number of ops:  13
compiled vars:  !0 = $data, !1 = $plugins
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   12     0  E >   RECV                                                 !0      
   14     1        INIT_FCALL                                                   'str_getcsv'
          2        FRAMELESS_ICALL_3                str_replace         ~2      '%22%22', ''
          3        OP_DATA                                                      !0
          4        SEND_VAL                                                     ~2
          5        DO_ICALL                                             $3      
          6        ASSIGN                                                       !1, $3
   16     7        INIT_FCALL                                                   'array_filter'
          8        SEND_VAR                                                     !1
          9        SEND_VAL                                                     'is_valid_plugin_slug'
         10        DO_ICALL                                             $5      
         11      > RETURN                                                       $5
   17    12*     > RETURN                                                       null

End of function str_getcsv_augmented

Function extract_required_plugins_from_header:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 28
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 26
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/Uudsc
function name:  extract_required_plugins_from_header
number of ops:  65
compiled vars:  !0 = $required, !1 = $matches, !2 = $slugs
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   20     0  E >   RECV                                                 !0      
   22     1        BOOL_NOT                                             ~3      !0
          2      > JMPNZ_EX                                             ~3      ~3, ->9
          3    >   INIT_FCALL                                                   'substr_count'
          4        SEND_VAR                                                     !0
          5        SEND_VAL                                                     '%22'
          6        DO_ICALL                                             $4      
          7        IS_SMALLER                                           ~5      $4, 2
          8        BOOL                                                 ~3      ~5
          9    > > JMPZ                                                         ~3, ->28
   23    10    > > JMPZ                                                         !0, ->26
         11    >   INIT_FCALL                                                   'array_filter'
         12        INIT_FCALL                                                   'array_map'
         13        SEND_VAL                                                     'trim'
         14        INIT_FCALL                                                   'explode'
         15        SEND_VAL                                                     '%2C'
         16        FRAMELESS_ICALL_3                str_replace         ~6      '%22', ''
         17        OP_DATA                                                      !0
         18        SEND_VAL                                                     ~6
         19        DO_ICALL                                             $7      
         20        SEND_VAR                                                     $7
         21        DO_ICALL                                             $8      
         22        SEND_VAR                                                     $8
         23        DO_ICALL                                             $9      
         24        QM_ASSIGN                                            ~10     $9
         25      > JMP                                                          ->27
         26    >   QM_ASSIGN                                            ~10     <array>
         27    > > RETURN                                                       ~10
   26    28    >   FRAMELESS_ICALL_3                str_replace         ~11     '%22%22', ''
         29        OP_DATA                                                      !0
         30        ASSIGN                                                       !0, ~11
   27    31        INIT_FCALL                                                   'preg_match_all'
         32        SEND_VAL                                                     '%23%22%28%5B%5E%22%5D%2B%29%22%23'
         33        SEND_VAR                                                     !0
         34        SEND_REF                                                     !1
         35        DO_ICALL                                                     
   29    36        INIT_FCALL                                                   'array_filter'
         37        INIT_FCALL                                                   'array_map'
         38        SEND_VAL                                                     'trim'
         39        INIT_FCALL                                                   'explode'
         40        SEND_VAL                                                     '%2C'
         41        INIT_FCALL                                                   'array_fill_keys'
         42        FETCH_DIM_R                                          ~14     !1, 0
         43        SEND_VAL                                                     ~14
         44        SEND_VAL                                                     ''
         45        DO_ICALL                                             $15     
         46        FRAMELESS_ICALL_2                strtr               ~16     !0, $15
         47        SEND_VAL                                                     ~16
         48        DO_ICALL                                             $17     
         49        SEND_VAR                                                     $17
         50        DO_ICALL                                             $18     
         51        SEND_VAR                                                     $18
         52        DO_ICALL                                             $19     
         53        ASSIGN                                                       !2, $19
   31    54        INIT_FCALL                                                   'array_merge'
         55        INIT_FCALL                                                   'array_filter'
         56        FETCH_DIM_R                                          ~21     !1, 1
         57        SEND_VAL                                                     ~21
         58        SEND_VAL                                                     'is_valid_plugin_slug'
         59        DO_ICALL                                             $22     
         60        SEND_VAR                                                     $22
         61        SEND_VAR                                                     !2
         62        DO_ICALL                                             $23     
         63      > RETURN                                                       $23
   32    64*     > RETURN                                                       null

End of function extract_required_plugins_from_header

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
205.77 ms | 2246 KiB | 34 Q