php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42037 fgetc() retuns one char when fails to read on php6
Submitted: 2007-07-18 17:04 UTC Modified: 2008-02-09 19:51 UTC
From: kraghuba at in dot ibm dot com Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 6CVS-2007-07-18 (snap) OS: RHEL 5
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kraghuba at in dot ibm dot com
New email:
PHP Version: OS:

 

 [2007-07-18 17:04 UTC] kraghuba at in dot ibm dot com
Description:
------------
fgets() returns a charecter when it fails to read from file because of following reasons: 
   1. file pointer already points to end of the file(file opened in mode) 
   2. File is opened in the write only mode

Only applicable to php6.

PHP Version:
PHP 6.0.0-dev (cli) (built: Jul 18 2007 20:53:03) (GCOV)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2007 Zend Technologies

OS: RHEL 5
Config : 
  ./configure --enable-gcov


Reproduce code:
---------------
<?php
  $file_handle = fopen("test.txt", "w");
  $data = "testing fgetc";
  fwrite($file_handle, $data);

  // rewind the file pointer to begining of the file
  var_dump( rewind($file_handle) );
  var_dump( ftell($file_handle) );
  var_dump( feof($file_handle) );

  // read from file
  var_dump( fgetc($file_handle) );
  var_dump( ftell($file_handle) );
  var_dump( feof($file_handle) );

  fseek($file_handle, 0, SEEK_END);
  var_dump( fgetc($file_handle) );

  fclose($file_handle);
  unlink("test.txt");
?>

Expected result:
----------------
bool(true)
int(0)
bool(false)
bool(false)
int(0)
bool(false)
bool(false)

Actual result:
--------------
bool(true)
int(0)
bool(false)
string(1) ""
int(0)
bool(true)
string(1) ""

output when run using run-test.php:
-----------------------------------
bool(true)
int(0)
bool(false)
string(1) "?"
int(0)
bool(true)
string(1) "?"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-09 19:51 UTC] felipe@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-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 03:01:28 2024 UTC