3v4l.org

run code in 300+ PHP versions simultaneously
<?php $temp = tempnam(sys_get_temp_dir(), 'csv_bug'); file_put_contents($temp, <<<'CSV' first,second foo,bar "foo baz",bar baz,bar CSV ); $expected = array( array('first', 'second'), array('foo', 'bar'), array("foo\nbaz", 'bar'), array('baz', 'bar'), ); $cases = array( 'drop newline' => \SplFileObject::DROP_NEW_LINE, 'skip empty' => \SplFileObject::SKIP_EMPTY, 'skip empty + read ahead' => \SplFileObject::SKIP_EMPTY | \SplFileObject::READ_AHEAD, 'drop newline + read ahead' => \SplFileObject::DROP_NEW_LINE | \SplFileObject::READ_AHEAD, 'drop newline + skip empty' => \SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY, 'all' => \SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY | \SplFileObject::READ_AHEAD, ); foreach ($cases as $name => $flags) { $file = new SplFileObject($temp); $file->setFlags($flags | \SplFileObject::READ_CSV); echo $name, "\n"; var_dump(iterator_to_array($file, false)); } var_dump('expected', $expected);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 34
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 34
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/MbRUS
function name:  (null)
number of ops:  40
compiled vars:  !0 = $temp, !1 = $expected, !2 = $cases, !3 = $flags, !4 = $name, !5 = $file
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'tempnam'
          1        INIT_FCALL                                               'sys_get_temp_dir'
          2        DO_ICALL                                         $6      
          3        SEND_VAR                                                 $6
          4        SEND_VAL                                                 'csv_bug'
          5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !0, $7
    4     7        INIT_FCALL                                               'file_put_contents'
          8        SEND_VAR                                                 !0
    5     9        SEND_VAL                                                 'first%2Csecond%0Afoo%2Cbar%0A%0A%22foo%0Abaz%22%2Cbar%0Abaz%2Cbar'
         10        DO_ICALL                                                 
   14    11        ASSIGN                                                   !1, <array>
   21    12        ASSIGN                                                   !2, <array>
   30    13      > FE_RESET_R                                       $12     !2, ->34
         14    > > FE_FETCH_R                                       ~13     $12, !3, ->34
         15    >   ASSIGN                                                   !4, ~13
   31    16        NEW                                              $15     'SplFileObject'
         17        SEND_VAR_EX                                              !0
         18        DO_FCALL                                      0          
         19        ASSIGN                                                   !5, $15
   32    20        INIT_METHOD_CALL                                         !5, 'setFlags'
         21        BW_OR                                            ~18     !3, 8
         22        SEND_VAL_EX                                              ~18
         23        DO_FCALL                                      0          
   34    24        ECHO                                                     !4
         25        ECHO                                                     '%0A'
   35    26        INIT_FCALL                                               'var_dump'
         27        INIT_FCALL                                               'iterator_to_array'
         28        SEND_VAR                                                 !5
         29        SEND_VAL                                                 <false>
         30        DO_ICALL                                         $20     
         31        SEND_VAR                                                 $20
         32        DO_ICALL                                                 
   30    33      > JMP                                                      ->14
         34    >   FE_FREE                                                  $12
   38    35        INIT_FCALL                                               'var_dump'
         36        SEND_VAL                                                 'expected'
         37        SEND_VAR                                                 !1
         38        DO_ICALL                                                 
         39      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
204.19 ms | 1400 KiB | 23 Q