From:             ryosuke_i_628 at yahoo dot co dot jp
Operating system: Windows
PHP version:      5.4.17
Package:          SPL related
Bug Type:         Bug
Bug description:On empty files, SplFileObject::fgets() returns not FALSE but 
EMPTY STRING

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 bug report at https://bugs.php.net/bug.php?id=65238&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=65238&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=65238&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=65238&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=65238&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=65238&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=65238&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=65238&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=65238&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=65238&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=65238&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=65238&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=65238&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=65238&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65238&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=65238&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=65238&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=65238&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65238&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=65238&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=65238&r=mysqlcfg

Reply via email to