|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66588 SplFileObject::fgetcsv incorrectly returns a row on premature EOF
Submitted: 2014-01-27 16:15 UTC Modified: 2021-07-06 11:57 UTC
From: jameshfisher at gmail dot com Assigned:
Status: Verified Package: SPL related
PHP Version: 5.5.8 OS: Ubuntu 12.04.4 LTS
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-01-27 16:15 UTC] jameshfisher at gmail dot com
From manual page:

Test script:
Assume the file `invalid.csv` contains:


Then run the script below:

    #!/usr/bin/env php5

    $s = new \SplFileObject('invalid.csv');

    $r = NULL;

    while (!$s->eof())

Expected result:
An error, signalled by FALSE, as described in the documentation for the method:

    $ ./test.php 

Actual result:
The cell in the file that does not have a closing quotation mark is treated as if EOF is the closing quotation mark. This is not compliant with the RFC:

    $ ./test.php 
    array(2) {
      string(4) "blah"
      string(5) "blah


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-28 19:50 UTC]
-Status: Open +Status: Verified
 [2020-04-09 08:11 UTC]
-Type: Bug +Type: Documentation Problem
 [2020-04-09 08:11 UTC]
This behavior is a deliberate design decision[1], so I don't think
this qualifies as bug; it's rather some form of error resilience.
Of course, that behavior should be documented.

If you, or anybody else, wants to have that behavior changed,
please provide a pull request[2], or start discussion on the
internals mailing list[3]; this bug tracker doesn't seem to be
appropriate for this kind of feature request.

[1] <>
[2] <>
[3] <>
 [2021-07-06 11:01 UTC]
-Type: Documentation Problem +Type: Bug
 [2021-07-06 11:01 UTC]
> This behavior is a deliberate design decision[1], […]

No, the behavior actually makes no sense.
 [2021-07-06 11:57 UTC]
To clarify: this is about the different behavior with and without
trailing newline (<>); both should behave
the same, and applying Postel's law, neither should return FALSE.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Jul 29 20:01:24 2021 UTC