ID: 49708 Comment by: orel at melix dot net Reported By: orel at melix dot net Status: Open Bug Type: Filesystem function related Operating System: All PHP Version: 5.3SVN-2009-09-29 (SVN) New Comment:
I agree with steven, doc and example should be updated or function should return FALSE (like fclose, fgets, fwrite ...) Patch for version 6 Index: ext/standard/file.c =================================================================== --- ext/standard/file.c (revision 288932) +++ ext/standard/file.c (working copy) @@ -2166,7 +2166,7 @@ &delimiter, &delimiter_len, &delimiter_type, &enclosure, &enclosure_len, &enclosure_type, &escape, &escape_len, &escape_type) == FAILURE) { - return; + RETURN_FALSE; } PHP_STREAM_TO_ZVAL(stream, &zstream); Patch for 5.3 Index: ext/standard/file.c =================================================================== --- ext/standard/file.c (revision 288932) +++ ext/standard/file.c (working copy) @@ -2034,7 +2034,7 @@ &enclosure_str, &enclosure_str_len, &escape_str, &escape_str_len) == FAILURE ) { - return; + RETURN_FALSE; } if (delimiter_str != NULL) { Previous Comments: ------------------------------------------------------------------------ [2009-09-29 11:59:52] orel at melix dot net Description: ------------ See example of documentation http://www.php.net/fgetcsv If file doesn't exist there is an endless loop. fgetcsv returns NULL if handler is invalid. Reproduce code: --------------- <?php $row = 1; $handle = fopen("test.csv", "r"); /* test.csv should not exist */ while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } } fclose($handle); ?> Expected result: ---------------- fgetcsv should returns FALSE Actual result: -------------- Endless loop, fgetcsv returns NULL ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49708&edit=1