3v4l.org

run code in 500+ PHP versions simultaneously
<?php function csv_reverse($handle, ...$csv_options) { $offsets = []; do { $offsets[] = ftell($handle); } while($row = fgetcsv($handle, ...$csv_options)); array_pop($offsets); // last offset is EOF for( $i=count($offsets)-1; $i>=0; --$i ) { fseek($handle, $offsets[$i]); yield fgetcsv($handle, ...$csv_options); } } $csv = <<<_E_ id,name,value 1,foo,"hello world" 2,bar,"hello world" 3, baz,"""hello world""" _E_; $in = fopen('php://memory', 'rwb'); fwrite($in, $csv); rewind($in); fgets($in); foreach( csv_reverse($in, null, ',', '"', '\\') as $row ) { var_dump($row); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 29
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/0sc8q
function name:  (null)
number of ops:  31
compiled vars:  !0 = $csv, !1 = $in, !2 = $row
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                       !0, 'id%2Cname%2Cvalue%0A1%2Cfoo%2C%22hello+world%22%0A2%2Cbar%2C%22hello+%0Aworld%22%0A3%2C+baz%2C%22%22%22hello+%0Aworld%22%22%22'
   25     1        INIT_FCALL                                                   'fopen'
          2        SEND_VAL                                                     'php%3A%2F%2Fmemory'
          3        SEND_VAL                                                     'rwb'
          4        DO_ICALL                                             $4      
          5        ASSIGN                                                       !1, $4
   26     6        INIT_FCALL                                                   'fwrite'
          7        SEND_VAR                                                     !1
          8        SEND_VAR                                                     !0
          9        DO_ICALL                                                     
   27    10        INIT_FCALL                                                   'rewind'
         11        SEND_VAR                                                     !1
         12        DO_ICALL                                                     
   28    13        INIT_FCALL                                                   'fgets'
         14        SEND_VAR                                                     !1
         15        DO_ICALL                                                     
   30    16        INIT_FCALL                                                   'csv_reverse'
         17        SEND_VAR                                                     !1
         18        SEND_VAL                                                     null
         19        SEND_VAL                                                     '%2C'
         20        SEND_VAL                                                     '%22'
         21        SEND_VAL                                                     '%5C'
         22        DO_FCALL                                          0  $9      
         23      > FE_RESET_R                                           $10     $9, ->29
         24    > > FE_FETCH_R                                                   $10, !2, ->29
   31    25    >   INIT_FCALL                                                   'var_dump'
         26        SEND_VAR                                                     !2
         27        DO_ICALL                                                     
   30    28      > JMP                                                          ->24
         29    >   FE_FREE                                                      $10
   32    30      > RETURN                                                       1

Function csv_reverse:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 4
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 23
Branch analysis from position: 37
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 23
Branch analysis from position: 37
Branch analysis from position: 23
Branch analysis from position: 4
filename:       /in/0sc8q
function name:  csv_reverse
number of ops:  38
compiled vars:  !0 = $handle, !1 = $csv_options, !2 = $offsets, !3 = $row, !4 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
          1        RECV_VARIADIC                                        !1      
          2        GENERATOR_CREATE                                             
    4     3        ASSIGN                                                       !2, <array>
    6     4    >   INIT_FCALL                                                   'ftell'
          5        SEND_VAR                                                     !0
          6        DO_ICALL                                             $7      
          7        ASSIGN_DIM                                                   !2
          8        OP_DATA                                                      $7
    7     9        INIT_FCALL                                                   'fgetcsv'
         10        SEND_VAR                                                     !0
         11        SEND_UNPACK                                                  !1
         12        CHECK_UNDEF_ARGS                                             
         13        DO_ICALL                                             $8      
         14        ASSIGN                                               ~9      !3, $8
         15      > JMPNZ                                                        ~9, ->4
    8    16    >   INIT_FCALL                                                   'array_pop'
         17        SEND_REF                                                     !2
         18        DO_ICALL                                                     
   10    19        COUNT                                                ~11     !2
         20        SUB                                                  ~12     ~11, 1
         21        ASSIGN                                                       !4, ~12
         22      > JMP                                                          ->35
   11    23    >   INIT_FCALL                                                   'fseek'
         24        SEND_VAR                                                     !0
         25        FETCH_DIM_R                                          ~14     !2, !4
         26        SEND_VAL                                                     ~14
         27        DO_ICALL                                                     
   12    28        INIT_FCALL                                                   'fgetcsv'
         29        SEND_VAR                                                     !0
         30        SEND_UNPACK                                                  !1
         31        CHECK_UNDEF_ARGS                                             
         32        DO_ICALL                                             $16     
         33        YIELD                                                        $16
   10    34        PRE_DEC                                                      !4
         35    >   IS_SMALLER_OR_EQUAL                                          0, !4
         36      > JMPNZ                                                        ~19, ->23
   14    37    > > GENERATOR_RETURN                                             

End of function csv_reverse

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.78 ms | 1829 KiB | 23 Q