3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * You can open a sample spreadsheet at https://goo.gl/j50MKc * You can download a sample CSV at https://goo.gl/H4ni63 */ $payload = '"Hello\", World!'; $rfcCsv = '"""Hello\"", World!"'; //Contents of https://goo.gl/H4ni63 $actualRfc = str_getcsv($rfcCsv, ',', '"', '"'); echo "READING RFC CSV\n"; echo "---------------\n"; echo "To read a well formatted CSV, you must use the `double-quote` char as enclosure and\n"; echo " as escape\n"; echo sprintf("Expected: %s\n", $payload); echo sprintf("Actual : %s\n", $actualRfc[0]); echo "Equals? "; var_dump($payload === $actualRfc[0]); echo "\n\n================================================================================\n\n"; $handler = fopen('php://temp', 'w+'); echo "WRITING\n"; echo "-------\n"; if (PHP_VERSION_ID < 50504 || (defined('HHVM_VERSION_ID') && HHVM_VERSION_ID < 31100)) { // There is NO support for escape param fputcsv($handler, array($payload), ',', '"'); } else { // There is support for escape param fputcsv($handler, array($payload), ',', '"', '"'); } rewind($handler); $actual = rtrim(fgets($handler, 4096), "\n"); echo "There is no way to write a well formatted CSV even. The support for the escape param\n"; echo " in the fputcsv function do not fix the invalid format.\n"; echo sprintf("Expected: %s\n", $rfcCsv); echo sprintf("Actual : %s\n", $actual); echo "Equals? "; var_dump($rfcCsv === $actual); echo "\n\n================================================================================\n\n"; $actualPhp = str_getcsv($actual, ',', '"', '"'); echo "READING PHP CSV\n"; echo "---------------\n"; echo "If you read a PHP formatted CSV using use the `double-quote` char as enclosure and\n"; echo " as escape, the result is not the expected one.\n"; echo sprintf("Expected: %s\n", $payload); echo sprintf("Actual : %s\n", $actualPhp[0]); echo "Equals? "; var_dump($payload === $actualPhp[0]); echo "\n\n================================================================================\n\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 40, Position 2 = 43
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 53
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
filename:       /in/NnHp4
function name:  (null)
number of ops:  121
compiled vars:  !0 = $payload, !1 = $rfcCsv, !2 = $actualRfc, !3 = $handler, !4 = $actual, !5 = $actualPhp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   ASSIGN                                                   !0, '%22Hello%5C%22%2C+World%21'
    8     1        ASSIGN                                                   !1, '%22%22%22Hello%5C%22%22%2C+World%21%22'
   10     2        INIT_FCALL                                               'str_getcsv'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 '%2C'
          5        SEND_VAL                                                 '%22'
          6        SEND_VAL                                                 '%22'
          7        DO_ICALL                                         $8      
          8        ASSIGN                                                   !2, $8
   11     9        ECHO                                                     'READING+RFC+CSV%0A'
   12    10        ECHO                                                     '---------------%0A'
   13    11        ECHO                                                     'To+read+a+well+formatted+CSV%2C+you+must+use+the+%60double-quote%60+char+as+enclosure+and%0A'
   14    12        ECHO                                                     '+as+escape%0A'
   15    13        INIT_FCALL                                               'sprintf'
         14        SEND_VAL                                                 'Expected%3A+%25s%0A'
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                         $10     
         17        ECHO                                                     $10
   16    18        INIT_FCALL                                               'sprintf'
         19        SEND_VAL                                                 'Actual++%3A+%25s%0A'
         20        FETCH_DIM_R                                      ~11     !2, 0
         21        SEND_VAL                                                 ~11
         22        DO_ICALL                                         $12     
         23        ECHO                                                     $12
   17    24        ECHO                                                     'Equals%3F+'
         25        INIT_FCALL                                               'var_dump'
         26        FETCH_DIM_R                                      ~13     !2, 0
         27        IS_IDENTICAL                                     ~14     !0, ~13
         28        SEND_VAL                                                 ~14
         29        DO_ICALL                                                 
   18    30        ECHO                                                     '%0A%0A%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0A%0A'
   20    31        INIT_FCALL                                               'fopen'
         32        SEND_VAL                                                 'php%3A%2F%2Ftemp'
         33        SEND_VAL                                                 'w%2B'
         34        DO_ICALL                                         $16     
         35        ASSIGN                                                   !3, $16
   21    36        ECHO                                                     'WRITING%0A'
   22    37        ECHO                                                     '-------%0A'
   23    38        DEFINED                                          ~18     'HHVM_VERSION_ID'
         39      > JMPZ_EX                                          ~18     ~18, ->43
         40    >   FETCH_CONSTANT                                   ~19     'HHVM_VERSION_ID'
         41        IS_SMALLER                                       ~20     ~19, 31100
         42        BOOL                                             ~18     ~20
         43    >   BOOL                                             ~21     ~18
         44      > JMPZ                                                     ~21, ->53
   25    45    >   INIT_FCALL                                               'fputcsv'
         46        SEND_VAR                                                 !3
         47        INIT_ARRAY                                       ~22     !0
         48        SEND_VAL                                                 ~22
         49        SEND_VAL                                                 '%2C'
         50        SEND_VAL                                                 '%22'
         51        DO_ICALL                                                 
   23    52      > JMP                                                      ->61
   28    53    >   INIT_FCALL                                               'fputcsv'
         54        SEND_VAR                                                 !3
         55        INIT_ARRAY                                       ~24     !0
         56        SEND_VAL                                                 ~24
         57        SEND_VAL                                                 '%2C'
         58        SEND_VAL                                                 '%22'
         59        SEND_VAL                                                 '%22'
         60        DO_ICALL                                                 
   30    61    >   INIT_FCALL                                               'rewind'
         62        SEND_VAR                                                 !3
         63        DO_ICALL                                                 
   31    64        INIT_FCALL                                               'rtrim'
         65        INIT_FCALL                                               'fgets'
         66        SEND_VAR                                                 !3
         67        SEND_VAL                                                 4096
         68        DO_ICALL                                         $27     
         69        SEND_VAR                                                 $27
         70        SEND_VAL                                                 '%0A'
         71        DO_ICALL                                         $28     
         72        ASSIGN                                                   !4, $28
   33    73        ECHO                                                     'There+is+no+way+to+write+a+well+formatted+CSV+even.+The+support+for+the+escape+param%0A'
   34    74        ECHO                                                     '+in+the+fputcsv+function+do+not+fix+the+invalid+format.%0A'
   35    75        INIT_FCALL                                               'sprintf'
         76        SEND_VAL                                                 'Expected%3A+%25s%0A'
         77        SEND_VAR                                                 !1
         78        DO_ICALL                                         $30     
         79        ECHO                                                     $30
   36    80        INIT_FCALL                                               'sprintf'
         81        SEND_VAL                                                 'Actual++%3A+%25s%0A'
         82        SEND_VAR                                                 !4
         83        DO_ICALL                                         $31     
         84        ECHO                                                     $31
   37    85        ECHO                                                     'Equals%3F+'
         86        INIT_FCALL                                               'var_dump'
         87        IS_IDENTICAL                                     ~32     !1, !4
         88        SEND_VAL                                                 ~32
         89        DO_ICALL                                                 
   38    90        ECHO                                                     '%0A%0A%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0A%0A'
   40    91        INIT_FCALL                                               'str_getcsv'
         92        SEND_VAR                                                 !4
         93        SEND_VAL                                                 '%2C'
         94        SEND_VAL                                                 '%22'
         95        SEND_VAL                                                 '%22'
         96        DO_ICALL                                         $34     
         97        ASSIGN                                                   !5, $34
   41    98        ECHO                                                     'READING+PHP+CSV%0A'
   42    99        ECHO                                                     '---------------%0A'
   43   100        ECHO                                                     'If+you+read+a+PHP+formatted+CSV+using+use+the+%60double-quote%60+char+as+enclosure+and%0A'
   44   101        ECHO                                                     '+as+escape%2C+the+result+is+not+the+expected+one.%0A'
   45   102        INIT_FCALL                                               'sprintf'
        103        SEND_VAL                                                 'Expected%3A+%25s%0A'
        104        SEND_VAR                                                 !0
        105        DO_ICALL                                         $36     
        106        ECHO                                                     $36
   46   107        INIT_FCALL                                               'sprintf'
        108        SEND_VAL                                                 'Actual++%3A+%25s%0A'
        109        FETCH_DIM_R                                      ~37     !5, 0
        110        SEND_VAL                                                 ~37
        111        DO_ICALL                                         $38     
        112        ECHO                                                     $38
   47   113        ECHO                                                     'Equals%3F+'
        114        INIT_FCALL                                               'var_dump'
        115        FETCH_DIM_R                                      ~39     !5, 0
        116        IS_IDENTICAL                                     ~40     !0, ~39
        117        SEND_VAL                                                 ~40
        118        DO_ICALL                                                 
   48   119        ECHO                                                     '%0A%0A%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0A%0A'
        120      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.99 ms | 1470 KiB | 21 Q