@@ -2050,11 +2050,24 @@ PHP_FUNCTION(fgetcsv)
2050
2050
}
2051
2051
}
2052
2052
2053
- php_fgetcsv (stream , delimiter , enclosure , escape , buf_len , buf , return_value );
2053
+ HashTable * values = php_fgetcsv (stream , delimiter , enclosure , escape , buf_len , buf );
2054
+ if (values == NULL ) {
2055
+ values = php_bc_fgetcsv_empty_line ();
2056
+ }
2057
+ RETURN_ARR (values );
2054
2058
}
2055
2059
/* }}} */
2056
2060
2057
- PHPAPI void php_fgetcsv (php_stream * stream , char delimiter , char enclosure , int escape_char , size_t buf_len , char * buf , zval * return_value ) /* {{{ */
2061
+ PHPAPI HashTable * php_bc_fgetcsv_empty_line (void )
2062
+ {
2063
+ HashTable * values = zend_new_array (1 );
2064
+ zval tmp ;
2065
+ ZVAL_NULL (& tmp );
2066
+ zend_hash_next_index_insert (values , & tmp );
2067
+ return values ;
2068
+ }
2069
+
2070
+ PHPAPI HashTable * php_fgetcsv (php_stream * stream , char delimiter , char enclosure , int escape_char , size_t buf_len , char * buf ) /* {{{ */
2058
2071
{
2059
2072
char * temp , * bptr , * line_end , * limit ;
2060
2073
size_t temp_len , line_end_len ;
@@ -2078,12 +2091,11 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, int
2078
2091
temp_len = buf_len ;
2079
2092
temp = emalloc (temp_len + line_end_len + 1 );
2080
2093
2081
- /* Initialize return array */
2082
- array_init ( return_value );
2094
+ /* Initialize values HashTable */
2095
+ HashTable * values = zend_new_array ( 0 );
2083
2096
2084
2097
/* Main loop to read CSV fields */
2085
- /* NB this routine will return a single null entry for a blank line */
2086
-
2098
+ /* NB this routine will return NULL for a blank line */
2087
2099
do {
2088
2100
char * comp_end , * hunk_begin ;
2089
2101
char * tptr = temp ;
@@ -2100,7 +2112,8 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, int
2100
2112
}
2101
2113
2102
2114
if (first_field && bptr == line_end ) {
2103
- add_next_index_null (return_value );
2115
+ zend_array_destroy (values );
2116
+ values = NULL ;
2104
2117
break ;
2105
2118
}
2106
2119
first_field = false;
@@ -2298,13 +2311,18 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, int
2298
2311
2299
2312
/* 3. Now pass our field back to php */
2300
2313
* comp_end = '\0' ;
2301
- add_next_index_stringl (return_value , temp , comp_end - temp );
2314
+
2315
+ zval z_tmp ;
2316
+ ZVAL_STRINGL (& z_tmp , temp , comp_end - temp );
2317
+ zend_hash_next_index_insert (values , & z_tmp );
2302
2318
} while (inc_len > 0 );
2303
2319
2304
2320
efree (temp );
2305
2321
if (stream ) {
2306
2322
efree (buf );
2307
2323
}
2324
+
2325
+ return values ;
2308
2326
}
2309
2327
/* }}} */
2310
2328
0 commit comments