Edit report at https://bugs.php.net/bug.php?id=65238&edit=1

 ID:                 65238
 Updated by:         a...@php.net
 Reported by:        ryosuke_i_628 at yahoo dot co dot jp
 Summary:            On empty files, SplFileObject::fgets() returns not
                     FALSE but EMPTY STRING
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            SPL related
 Operating System:   Windows
 PHP Version:        5.4.17
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The docs:

Returns a string containing the next line from the file, or FALSE on error.

How it flows:

1. iteration
$file->eof()         -> false
echo $file->fgets(); -> ""
2. iteration
$file->eof()         -> true

You would have false/exception if say you delete the file between ->eof() and -
>fgets(), but without an error the flow is pretty matching. If you think your 
example should go onto the docs page, please feel free to extend it.


Previous Comments:
------------------------------------------------------------------------
[2013-07-10 17:46:41] ryosuke_i_628 at yahoo dot co dot jp

Description:
------------
I don't know whether this is a bug or a documentation problem.

In SplFileObject::fgets documentation,

Example is shown as following:
<?php
$file = new SplFileObject("file.txt");
while (!$file->eof()) {
    echo $file->fgets();
}
?>

But this should be:
<?php
$file = new SplFileObject("file.txt");
while (($buffer = $file->fgets("file.txt")) !== "") {
    echo $buffer;
}
?>

I show you the test script.

Test script:
---------------
<?php

$arr = array();
$file = new SplFileObject("empty_file.txt");
while (!$file->eof()) {
    $arr[] = $file->fgets();
}
var_dump($arr);

Expected result:
----------------
array(1) {
  [0]=>
  bool(false)
}

# Actually, this substitution should not occurr.

Actual result:
--------------
array(1) {
  [0]=>
  string(0) ""
}

# I think this can give us lots confusion.


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65238&edit=1

Reply via email to