php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45585 fread() return value for EOF inconsistent between PHP 5 and 6
Submitted: 2008-07-21 16:33 UTC Modified: 2008-11-11 00:42 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jani@php.net Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 6CVS-2008-07-21 (CVS) OS: *
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: jani@php.net
New email:
PHP Version: OS:

 

 [2008-07-21 16:33 UTC] jani@php.net
Description:
------------
# echo "1" > /tmp/test.txt

# php_5_2/sapi/cli/php -n -r '$fp=fopen("/tmp/test.txt", "r"); while(1) {$a=fread($fp, 8192); if (!$a) {var_dump($a); exit;}}'
string(0) ""

# php_5_3/sapi/cli/php -n -r '$fp=fopen("/tmp/test.txt", "r"); while(1) {$a=fread($fp, 8192); if (!$a) {var_dump($a); exit;}}'
string(0) ""

# php_6/sapi/cli/php -n -r '$fp=fopen("/tmp/test.txt", "r"); while(1) {$a=fread($fp, 8192); if (!$a) {var_dump($a); exit;}}'
bool(false)



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-21 16:34 UTC] jani@php.net
In 5.2/5.3 it returns empty string, in PHP 6 FALSE.
 [2008-10-21 07:25 UTC] mike at mikegerwitz dot com
Confirmed in php6.0-200810110430. Cannot reliably loop through data using feof() when recognizing FALSE as an error.

while ( !( feof( $handle ) ) )
{
    if ( ( $text = fread( $handle, 1024 ) ) === FALSE )
    {
        // When attempting to read past the EOF, PHP 6 returns FALSE rather than an empty string
        die( 'Error!' );
    }
    $data .= $text;
}

In PHP < 6, the above code will not display the error. In PHP 6, it does a good job of breaking a lot of code. Is this new functionality intended or are there plans to fix it?
 [2008-11-11 00:42 UTC] lbarnaud@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jan 05 05:01:28 2025 UTC