3v4l.org

run code in 300+ 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
         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
         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
         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:  8
compiled vars:  !0 = $slug
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        INIT_FCALL                                               'trim'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '%2C+%09%0A%0D%00%0B'
          4        DO_ICALL                                         $1      
          5        IS_NOT_IDENTICAL                                 ~2      $1, ''
          6      > RETURN                                                   ~2
   10     7*     > 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:  16
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        INIT_FCALL                                               'str_replace'
          3        SEND_VAL                                                 '%22%22'
          4        SEND_VAL                                                 ''
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $2      
          7        SEND_VAR                                                 $2
          8        DO_ICALL                                         $3      
          9        ASSIGN                                                   !1, $3
   16    10        INIT_FCALL                                               'array_filter'
         11        SEND_VAR                                                 !1
         12        SEND_VAL                                                 'is_valid_plugin_slug'
         13        DO_ICALL                                         $5      
         14      > RETURN                                                   $5
   17    15*     > 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 = 31
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 29
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
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:  74
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, ->31
   23    10    > > JMPZ                                                     !0, ->29
         11    >   INIT_FCALL                                               'array_filter'
         12        INIT_FCALL                                               'array_map'
         13        SEND_VAL                                                 'trim'
         14        INIT_FCALL                                               'explode'
         15        SEND_VAL                                                 '%2C'
         16        INIT_FCALL                                               'str_replace'
         17        SEND_VAL                                                 '%22'
         18        SEND_VAL                                                 ''
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $6      
         21        SEND_VAR                                                 $6
         22        DO_ICALL                                         $7      
         23        SEND_VAR                                                 $7
         24        DO_ICALL                                         $8      
         25        SEND_VAR                                                 $8
         26        DO_ICALL                                         $9      
         27        QM_ASSIGN                                        ~10     $9
         28      > JMP                                                      ->30
         29    >   QM_ASSIGN                                        ~10     <array>
         30    > > RETURN                                                   ~10
   26    31    >   INIT_FCALL                                               'str_replace'
         32        SEND_VAL                                                 '%22%22'
         33        SEND_VAL                                                 ''
         34        SEND_VAR                                                 !0
         35        DO_ICALL                                         $11     
         36        ASSIGN                                                   !0, $11
   27    37        INIT_FCALL                                               'preg_match_all'
         38        SEND_VAL                                                 '%23%22%28%5B%5E%22%5D%2B%29%22%23'
         39        SEND_VAR                                                 !0
         40        SEND_REF                                                 !1
         41        DO_ICALL                                                 
   29    42        INIT_FCALL                                               'array_filter'
         43        INIT_FCALL                                               'array_map'
         44        SEND_VAL                                                 'trim'
         45        INIT_FCALL                                               'explode'
         46        SEND_VAL                                                 '%2C'
         47        INIT_FCALL                                               'strtr'
         48        SEND_VAR                                                 !0
         49        INIT_FCALL                                               'array_fill_keys'
         50        FETCH_DIM_R                                      ~14     !1, 0
         51        SEND_VAL                                                 ~14
         52        SEND_VAL                                                 ''
         53        DO_ICALL                                         $15     
         54        SEND_VAR                                                 $15
         55        DO_ICALL                                         $16     
         56        SEND_VAR                                                 $16
         57        DO_ICALL                                         $17     
         58        SEND_VAR                                                 $17
         59        DO_ICALL                                         $18     
         60        SEND_VAR                                                 $18
         61        DO_ICALL                                         $19     
         62        ASSIGN                                                   !2, $19
   31    63        INIT_FCALL                                               'array_merge'
         64        INIT_FCALL                                               'array_filter'
         65        FETCH_DIM_R                                      ~21     !1, 1
         66        SEND_VAL                                                 ~21
         67        SEND_VAL                                                 'is_valid_plugin_slug'
         68        DO_ICALL                                         $22     
         69        SEND_VAR                                                 $22
         70        SEND_VAR                                                 !2
         71        DO_ICALL                                         $23     
         72      > RETURN                                                   $23
   32    73*     > RETURN                                                   null

End of function extract_required_plugins_from_header

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.55 ms | 1411 KiB | 43 Q