php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61048 fgetcsv() length of 0 DOES NOT mean unlimited maximum line length
Submitted: 2012-02-10 18:28 UTC Modified: 2014-12-02 14:11 UTC
Votes:3
Avg. Score:3.3 ± 1.7
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: blajoie55 at gmail dot com Assigned: datibbaw (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: blajoie55 at gmail dot com
New email:
PHP Version: OS:

 

 [2012-02-10 18:28 UTC] blajoie55 at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.fgetcsv#refsect1-function.fgetcsv-
parameters
---

The documentation states the following for the length parameter for fgetcsv():

"Must be greater than the longest line (in characters) to be found in the CSV 
file (allowing for trailing line-end characters). It became optional in PHP 5. 
Omitting this parameter (or setting it to 0 in PHP 5.0.4 and later) the maximum 
line length is not limited, which is slightly slower."

This is wrong. I have a php 5.0.4 environment using fgetcsv() in a while loop as 
follows:

fgetcsv($csvHandle, 0, self::DELIMITER);

And the 0 does not put no limit on the max line length, instead the fgetcsv() 
call gets each individual character on the line in the file


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-10 18:43 UTC] blajoie55 at gmail dot com
-Summary: length of 0 DOES NOT mean unlimited maximum line length +Summary: fgetcsv() length of 0 DOES NOT mean unlimited maximum line length
 [2012-02-10 18:43 UTC] blajoie55 at gmail dot com
updating summary
 [2012-02-12 05:20 UTC] phpmpan at mpan dot pl
Confirmed. 5.0.4 uses code from r181491 (in 5.0 branch), which sets length to 1 if 0 is passed as the second argument. The behaviour described by the documentation was introduced by r181490 (in 5.1).

Therefore the documentation should be changed to:

"Omitting this parameter (or setting it to 0 in PHP 5.1.0 and later) the maximum line length is not limited, which is slightly slower."
 [2014-02-13 01:05 UTC] cmbecker69 at gmx dot de
Confirmed by testing on Win7. PHP 5.0.4 (and 5.0.5) treats
$length=0 as $length=1, while PHP 5.1.0 treats it as infinite
(well, at least 131073).
 [2014-04-25 14:36 UTC] cmbecker69 at gmx dot de
As the documentation was properly updated, this ticket should be
closed.
 [2014-12-02 14:11 UTC] datibbaw@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: datibbaw
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 13:00:01 2026 UTC