3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CsvFileObject extends \SplFileObject { use CsvFileObjectTrait; public function __construct($filename, $open_mode='r', $use_include_path=false, $context=null) { parent::__construct($filename, $open_mode, $use_include_path, $context); $this->fixCsvControl(); } } class CsvTempFileObject extends \SplTempFileObject { use CsvFileObjectTrait; public function __construct ($max_memory=null) { parent::__construct($max_memory); $this->fixCsvControl(); } } trait CsvFileObjectTrait { protected function fixCsvControl() { list($delimiter, $enclosure) = $this->getCsvControl(); $this->setCsvControl($delimiter, $enclosure); } public function fgetcsv($delimiter=",", $enclosure='"', $escape='"') { return parent::fgetcsv($delimiter, $enclosure, $enclosure, $escape='"'); } public function fputcsv($fields, $delimiter=',', $enclosure='"', $escape='"') { $this->fwrite(str_putcsv_rfc($fields, $delimiter, $enclosure)); } public function setCsvControl($delimiter=",", $enclosure='"', $escape='"') { parent::setCsvControl($delimiter, $enclosure, $enclosure); } } function fputcsv_rfc($handle, $fields, $delimiter=',', $enclosure='"') { fwrite($handle, str_putcsv_rfc($fields, $delimiter, $enclosure)); } function fgetcsv_rfc($handle, $length=0, $delimiter=",", $enclosure='"') { return fgetcsv($handle, $length, $delimiter, $enclosure, $enclosure); } function str_getcsv_rfc($input, $delimiter=",", $enclosure='"') { return str_getcsv ($input, $delimiter, $enclosure, $enclosure); } function str_putcsv_rfc($fields, $delimiter=",", $enclosure='"') { $file = new SplTempFileObject(); $file->fputcsv($fields, $delimiter, $enclosure); $file->rewind(); $line = ''; while (!$file->eof()) { $line .= $file->fgets(); } return str_replace('\\'.$enclosure, '\\'.$enclosure.$enclosure, $line); } $a = new CsvTempFileObject(); $a->fwrite('"Hello \""World""!"'."\n"); $a->rewind(); $a->setFlags(CsvTempFileObject::READ_CSV); foreach ($a as $fields) { var_dump($fields); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/k2o3i
function name:  (null)
number of ops:  22
compiled vars:  !0 = $a, !1 = $fields
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'csvfileobject', 'splfileobject'
   14     1        DECLARE_CLASS                                            'csvtempfileobject', 'spltempfileobject'
   78     2        NEW                                              $2      'CsvTempFileObject'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $2
   79     5        INIT_METHOD_CALL                                         !0, 'fwrite'
          6        SEND_VAL_EX                                              '%22Hello+%5C%22%22World%22%22%21%22%0A'
          7        DO_FCALL                                      0          
   80     8        INIT_METHOD_CALL                                         !0, 'rewind'
          9        DO_FCALL                                      0          
   81    10        INIT_METHOD_CALL                                         !0, 'setFlags'
         11        FETCH_CLASS_CONSTANT                             ~7      'CsvTempFileObject', 'READ_CSV'
         12        SEND_VAL_EX                                              ~7
         13        DO_FCALL                                      0          
   82    14      > FE_RESET_R                                       $9      !0, ->20
         15    > > FE_FETCH_R                                               $9, !1, ->20
   83    16    >   INIT_FCALL                                               'var_dump'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                                 
   82    19      > JMP                                                      ->15
         20    >   FE_FREE                                                  $9
   84    21      > RETURN                                                   1

Function fputcsv_rfc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k2o3i
function name:  fputcsv_rfc
number of ops:  14
compiled vars:  !0 = $handle, !1 = $fields, !2 = $delimiter, !3 = $enclosure
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      '%2C'
          3        RECV_INIT                                        !3      '%22'
   51     4        INIT_FCALL                                               'fwrite'
          5        SEND_VAR                                                 !0
          6        INIT_FCALL_BY_NAME                                       'str_putcsv_rfc'
          7        SEND_VAR_EX                                              !1
          8        SEND_VAR_EX                                              !2
          9        SEND_VAR_EX                                              !3
         10        DO_FCALL                                      0  $4      
         11        SEND_VAR                                                 $4
         12        DO_ICALL                                                 
   52    13      > RETURN                                                   null

End of function fputcsv_rfc

Function fgetcsv_rfc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k2o3i
function name:  fgetcsv_rfc
number of ops:  13
compiled vars:  !0 = $handle, !1 = $length, !2 = $delimiter, !3 = $enclosure
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
          2        RECV_INIT                                        !2      '%2C'
          3        RECV_INIT                                        !3      '%22'
   56     4        INIT_FCALL                                               'fgetcsv'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !1
          7        SEND_VAR                                                 !2
          8        SEND_VAR                                                 !3
          9        SEND_VAR                                                 !3
         10        DO_ICALL                                         $4      
         11      > RETURN                                                   $4
   57    12*     > RETURN                                                   null

End of function fgetcsv_rfc

Function str_getcsv_rfc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k2o3i
function name:  str_getcsv_rfc
number of ops:  11
compiled vars:  !0 = $input, !1 = $delimiter, !2 = $enclosure
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '%2C'
          2        RECV_INIT                                        !2      '%22'
   61     3        INIT_FCALL                                               'str_getcsv'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        SEND_VAR                                                 !2
          7        SEND_VAR                                                 !2
          8        DO_ICALL                                         $3      
          9      > RETURN                                                   $3
   62    10*     > RETURN                                                   null

End of function str_getcsv_rfc

Function str_putcsv_rfc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 15
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 15
Branch analysis from position: 22
Branch analysis from position: 15
filename:       /in/k2o3i
function name:  str_putcsv_rfc
number of ops:  32
compiled vars:  !0 = $fields, !1 = $delimiter, !2 = $enclosure, !3 = $file, !4 = $line
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '%2C'
          2        RECV_INIT                                        !2      '%22'
   66     3        NEW                                              $5      'SplTempFileObject'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !3, $5
   67     6        INIT_METHOD_CALL                                         !3, 'fputcsv'
          7        SEND_VAR_EX                                              !0
          8        SEND_VAR_EX                                              !1
          9        SEND_VAR_EX                                              !2
         10        DO_FCALL                                      0          
   68    11        INIT_METHOD_CALL                                         !3, 'rewind'
         12        DO_FCALL                                      0          
   70    13        ASSIGN                                                   !4, ''
   71    14      > JMP                                                      ->18
   72    15    >   INIT_METHOD_CALL                                         !3, 'fgets'
         16        DO_FCALL                                      0  $11     
         17        ASSIGN_OP                                     8          !4, $11
   71    18    >   INIT_METHOD_CALL                                         !3, 'eof'
         19        DO_FCALL                                      0  $13     
         20        BOOL_NOT                                         ~14     $13
         21      > JMPNZ                                                    ~14, ->15
   75    22    >   INIT_FCALL                                               'str_replace'
         23        CONCAT                                           ~15     '%5C', !2
         24        SEND_VAL                                                 ~15
         25        CONCAT                                           ~16     '%5C', !2
         26        CONCAT                                           ~17     ~16, !2
         27        SEND_VAL                                                 ~17
         28        SEND_VAR                                                 !4
         29        DO_ICALL                                         $18     
         30      > RETURN                                                   $18
   76    31*     > RETURN                                                   null

End of function str_putcsv_rfc

Class CsvFileObject:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k2o3i
function name:  __construct
number of ops:  13
compiled vars:  !0 = $filename, !1 = $open_mode, !2 = $use_include_path, !3 = $context
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      'r'
          2        RECV_INIT                                        !2      <false>
          3        RECV_INIT                                        !3      null
    9     4        INIT_STATIC_METHOD_CALL                                  
          5        SEND_VAR_EX                                              !0
          6        SEND_VAR_EX                                              !1
          7        SEND_VAR_EX                                              !2
          8        SEND_VAR_EX                                              !3
          9        DO_FCALL                                      0          
   10    10        INIT_METHOD_CALL                                         'fixCsvControl'
         11        DO_FCALL                                      0          
   11    12      > RETURN                                                   null

End of function __construct

End of class CsvFileObject.

Class CsvTempFileObject:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k2o3i
function name:  __construct
number of ops:  7
compiled vars:  !0 = $max_memory
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV_INIT                                        !0      null
   20     1        INIT_STATIC_METHOD_CALL                                  
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
   21     4        INIT_METHOD_CALL                                         'fixCsvControl'
          5        DO_FCALL                                      0          
   22     6      > RETURN                                                   null

End of function __construct

End of class CsvTempFileObject.

Class CsvFileObjectTrait:
Function fixcsvcontrol:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k2o3i
function name:  fixCsvControl
number of ops:  12
compiled vars:  !0 = $delimiter, !1 = $enclosure
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   INIT_METHOD_CALL                                         'getCsvControl'
          1        DO_FCALL                                      0  $2      
          2        FETCH_LIST_R                                     $3      $2, 0
          3        ASSIGN                                                   !0, $3
          4        FETCH_LIST_R                                     $5      $2, 1
          5        ASSIGN                                                   !1, $5
          6        FREE                                                     $2
   30     7        INIT_METHOD_CALL                                         'setCsvControl'
          8        SEND_VAR_EX                                              !0
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
   31    11      > RETURN                                                   null

End of function fixcsvcontrol

Function fgetcsv:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k2o3i
function name:  fgetcsv
number of ops:  12
compiled vars:  !0 = $delimiter, !1 = $enclosure, !2 = $escape
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV_INIT                                        !0      '%2C'
          1        RECV_INIT                                        !1      '%22'
          2        RECV_INIT                                        !2      '%22'
   35     3        INIT_STATIC_METHOD_CALL                                  'fgetcsv'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        SEND_VAR_EX                                              !1
          7        ASSIGN                                           ~3      !2, '%22'
          8        SEND_VAL_EX                                              ~3
          9        DO_FCALL                                      0  $4      
         10      > RETURN                                                   $4
   36    11*     > RETURN                                                   null

End of function fgetcsv

Function fputcsv:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k2o3i
function name:  fputcsv
number of ops:  13
compiled vars:  !0 = $fields, !1 = $delimiter, !2 = $enclosure, !3 = $escape
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '%2C'
          2        RECV_INIT                                        !2      '%22'
          3        RECV_INIT                                        !3      '%22'
   40     4        INIT_METHOD_CALL                                         'fwrite'
          5        INIT_FCALL_BY_NAME                                       'str_putcsv_rfc'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAR_EX                                              !1
          8        SEND_VAR_EX                                              !2
          9        DO_FCALL                                      0  $4      
         10        SEND_VAR_NO_REF_EX                                       $4
         11        DO_FCALL                                      0          
   41    12      > RETURN                                                   null

End of function fputcsv

Function setcsvcontrol:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k2o3i
function name:  setCsvControl
number of ops:  9
compiled vars:  !0 = $delimiter, !1 = $enclosure, !2 = $escape
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV_INIT                                        !0      '%2C'
          1        RECV_INIT                                        !1      '%22'
          2        RECV_INIT                                        !2      '%22'
   45     3        INIT_STATIC_METHOD_CALL                                  'setCsvControl'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0          
   46     8      > RETURN                                                   null

End of function setcsvcontrol

End of class CsvFileObjectTrait.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.46 ms | 1032 KiB | 18 Q