@@ -1959,6 +1959,9 @@ static zend_result spl_filesystem_file_read_csv(spl_filesystem_object *intern, c
1959
1959
}
1960
1960
1961
1961
php_fgetcsv (intern -> u .file .stream , delimiter , enclosure , escape , buf_len , buf , & intern -> u .file .current_zval );
1962
+ /* php_fgetcsv() only ever sets an array */
1963
+ ZEND_ASSERT (Z_TYPE (intern -> u .file .current_zval ) == IS_ARRAY );
1964
+
1962
1965
if (return_value ) {
1963
1966
ZVAL_COPY (return_value , & intern -> u .file .current_zval );
1964
1967
}
@@ -2011,34 +2014,30 @@ static bool spl_filesystem_file_is_empty_line(spl_filesystem_object *intern) /*
2011
2014
if (intern -> u .file .current_line ) {
2012
2015
return intern -> u .file .current_line_len == 0 ;
2013
2016
} else if (!Z_ISUNDEF (intern -> u .file .current_zval )) {
2014
- switch (Z_TYPE (intern -> u .file .current_zval )) {
2015
- case IS_STRING :
2016
- return Z_STRLEN (intern -> u .file .current_zval ) == 0 ;
2017
- case IS_ARRAY :
2018
- if (SPL_HAS_FLAG (intern -> flags , SPL_FILE_OBJECT_READ_CSV )
2019
- && zend_hash_num_elements (Z_ARRVAL (intern -> u .file .current_zval )) == 1 ) {
2020
- uint32_t idx = 0 ;
2021
- zval * first ;
2022
-
2023
- if (HT_IS_PACKED (Z_ARRVAL (intern -> u .file .current_zval ))) {
2024
- while (Z_ISUNDEF (Z_ARRVAL (intern -> u .file .current_zval )-> arPacked [idx ])) {
2025
- idx ++ ;
2026
- }
2027
- first = & Z_ARRVAL (intern -> u .file .current_zval )-> arPacked [idx ];
2028
- } else {
2029
- while (Z_ISUNDEF (Z_ARRVAL (intern -> u .file .current_zval )-> arData [idx ].val )) {
2030
- idx ++ ;
2031
- }
2032
- first = & Z_ARRVAL (intern -> u .file .current_zval )-> arData [idx ].val ;
2033
- }
2034
- return Z_TYPE_P (first ) == IS_STRING && Z_STRLEN_P (first ) == 0 ;
2017
+ ZEND_ASSERT (Z_TYPE (intern -> u .file .current_zval ) == IS_ARRAY );
2018
+ /* TODO Figure out when this branch can happen... */
2019
+ if (SPL_HAS_FLAG (intern -> flags , SPL_FILE_OBJECT_READ_CSV )
2020
+ && zend_hash_num_elements (Z_ARRVAL (intern -> u .file .current_zval )) == 1 ) {
2021
+ ZEND_ASSERT (false && "Can this happen?" );
2022
+ uint32_t idx = 0 ;
2023
+ zval * first ;
2024
+
2025
+ if (HT_IS_PACKED (Z_ARRVAL (intern -> u .file .current_zval ))) {
2026
+ while (Z_ISUNDEF (Z_ARRVAL (intern -> u .file .current_zval )-> arPacked [idx ])) {
2027
+ idx ++ ;
2028
+ }
2029
+ first = & Z_ARRVAL (intern -> u .file .current_zval )-> arPacked [idx ];
2030
+ ZEND_ASSERT (Z_TYPE_P (first ) == IS_STRING );
2031
+ } else {
2032
+ while (Z_ISUNDEF (Z_ARRVAL (intern -> u .file .current_zval )-> arData [idx ].val )) {
2033
+ idx ++ ;
2035
2034
}
2036
- return zend_hash_num_elements (Z_ARRVAL (intern -> u .file .current_zval )) == 0 ;
2037
- case IS_NULL :
2038
- return 1 ;
2039
- default :
2040
- return 0 ;
2035
+ first = & Z_ARRVAL (intern -> u .file .current_zval )-> arData [idx ].val ;
2036
+ ZEND_ASSERT (Z_TYPE_P (first ) == IS_STRING );
2037
+ }
2038
+ return Z_STRLEN_P (first ) == 0 ;
2041
2039
}
2040
+ return zend_hash_num_elements (Z_ARRVAL (intern -> u .file .current_zval )) == 0 ;
2042
2041
} else {
2043
2042
return 1 ;
2044
2043
}
@@ -2234,6 +2233,7 @@ PHP_METHOD(SplFileObject, current)
2234
2233
RETURN_STRINGL (intern -> u .file .current_line , intern -> u .file .current_line_len );
2235
2234
} else if (!Z_ISUNDEF (intern -> u .file .current_zval )) {
2236
2235
ZEND_ASSERT (!Z_ISREF (intern -> u .file .current_zval ));
2236
+ ZEND_ASSERT (Z_TYPE (intern -> u .file .current_zval ) == IS_ARRAY );
2237
2237
RETURN_COPY (& intern -> u .file .current_zval );
2238
2238
}
2239
2239
RETURN_FALSE ;
0 commit comments