php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #50221 fgetcsv error handling
Submitted: 2009-11-18 21:16 UTC Modified: 2009-11-19 08:53 UTC
From: none at example dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: linux
Private report: No CVE-ID: None
 [2009-11-18 21:16 UTC] none at example dot com
Description:
------------
Concerns official Example on:
http://de.php.net/manual/en/function.fgetcsv.php
and all other examples in the user feedback.

fgetcsv error handling shouldn't check ===FALSE, since reading from an unopened file will return NULL and cause a tight loop.

So don't do:

while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {

but just:

while ($data = fgetcsv($handle, 1000, ",")) {

This will properly read in empty lines, and not stay looping forever when $handle is undefined (possibly because of fopen() failing, since that error isn't handled.......)

Thanks!

Reproduce code:
---------------
---
From manual page: function.fgetcsv#Examples
---



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-19 08:53 UTC] svn@php.net
Automatic comment from SVN on behalf of rquadling
Revision: http://svn.php.net/viewvc/?view=revision&revision=290968
Log: Updated return types for invalid file handle. Updated example to include error checking for fopen(). Fix # 50221
 [2009-11-19 08:53 UTC] rquadling@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 23:00:01 2026 UTC