php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45759 feof(FALSE) should return TRUE
Submitted: 2008-08-08 09:44 UTC Modified: 2008-08-08 13:34 UTC
From: stuff at axxess dot co dot za Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.2.6 OS: Linux
Private report: No CVE-ID: None
 [2008-08-08 09:44 UTC] stuff at axxess dot co dot za
Description:
------------
feof(bad_fd) returns FALSE, which indicates that the file descriptor 
has more data.  This is wrong in *every* case.  It should return 
TRUE (no more data), or throw a fatal error.  More than a few sloppy 
fools fail to test the result of fopen(), and blow your bandwidth 
cap and/or hosting budget for a year by serving warnings when your 
RSS source changes their DNS name. 

Reproduce code:
---------------
<?php
$f = fopen ("http://dns.err/foo.html","r");  # ie. $f=FALSE
while (!feof ($f)) {                         # ie. !feof(FALSE)
  $verse .= fgets($f, 4096);
}
fclose ($f);
echo "DONE";


Expected result:
----------------
Warning: fopen(): php_network_getaddresses: getaddrinfo failed: Name 
or service not known in /home/andrewm/x.php on line 2

Warning: fopen(http://dns.err/foo.html): failed to open stream: No 
such file or directory in /home/andrewm/x.php on line 2

Warning: feof(): supplied argument is not a valid stream resource 
in /home/andrewm/x.php on line 3
DONE

Actual result:
--------------
Warning: fopen(): php_network_getaddresses: getaddrinfo failed: Name 
or service not known in /home/andrewm/x.php on line 2

Warning: fopen(http://dns.err/foo.html): failed to open stream: No 
such file or directory in /home/andrewm/x.php on line 2

Warning: feof(): supplied argument is not a valid stream resource 
in /home/andrewm/x.php on line 3

Warning: fgets(): supplied argument is not a valid stream resource 
in /home/andrewm/x.php on line 4

Warning: feof(): supplied argument is not a valid stream resource 
in /home/andrewm/x.php on line 3

Warning: fgets(): supplied argument is not a valid stream resource 
in /home/andrewm/x.php on line 4

Warning: feof(): supplied argument is not a valid stream resource 
in /home/andrewm/x.php on line 3

Warning: fgets(): supplied argument is not a valid stream resource 
in /home/andrewm/x.php on line 4

Warning: feof(): supplied argument is not a valid stream resource 
in /home/andrewm/x.php on line 3

Warning: fgets(): supplied argument is not a valid stream resource 
in /home/andrewm/x.php on line 4

(warnings continue ad-infinitum)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-08 10:58 UTC] felipe@php.net
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

That is expected, and it is documented:
- http://docs.php.net/feof

Thanks.
 [2008-08-08 13:34 UTC] stuff at axxess dot co dot za
I'm not saying it's undocumented - I did read the documentation. I'm 
saying it's objectively wrong, and can be modified without ill 
effects.  

feof() is an error checking function, and when it encounters an 
error, it should treat it as an error.  php is mapping the C stdio 
implementation here.  The C stdio implementation of feof does not 
support passing anything other than a FILE pointer.  Passing a 
non-file pointer will get you a fatal error (ie. a NULL pointer 
dereference and a core dump).  It is wrong that the php 
implementation should creatively return the no-error result for an 
error condition.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 20:01:29 2024 UTC