#50221 [Opn->Csd]: fgetcsv error handling

From: Date: Thu, 19 Nov 2009 08:53:40 +0000
Subject: #50221 [Opn->Csd]: fgetcsv error handling
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-3219@lists.php.net to get a copy of this message
ID: 50221 Updated by: rquadling@php.net Reported By: none at example dot com -Status: Open +Status: Closed Bug Type: Documentation problem Operating System: linux PHP Version: Irrelevant New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2009-11-19 08:53:30] 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-18 21:16:33] 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 --- ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50221&edit=1

« previous php.doc.bugs (#3219) next »