#45585 [Opn->Csd]: fread() return value for EOF inconsistent between PHP 5 and 6

From: Date: Tue, 11 Nov 2008 00:42:34 +0000
Subject: #45585 [Opn->Csd]: fread() return value for EOF inconsistent between PHP 5 and 6
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-130856@lists.php.net to get a copy of this message
ID: 45585 Updated by: lbarnaud@php.net Reported By: jani@php.net -Status: Open +Status: Closed Bug Type: Filesystem function related Operating System: * PHP Version: 6CVS-2008-07-21 (CVS) New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2008-10-21 07:25:53] 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-07-21 16:34:04] jani@php.net In 5.2/5.3 it returns empty string, in PHP 6 FALSE. ------------------------------------------------------------------------ [2008-07-21 16:33:34] 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) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45585&edit=1

« previous php.bugs (#130856) next »