#45759 [Bgs]: feof(FALSE) should return TRUE
| From: | stuff at axxess dot co dot za | Date: | Fri, 08 Aug 2008 13:34:19 +0000 |
| Subject: | #45759 [Bgs]: feof(FALSE) should return TRUE | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-127790@lists.php.net to get a copy of this message | ||
ID: 45759
User updated by: stuff at axxess dot co dot za
Reported By: stuff at axxess dot co dot za
Status: Bogus
Bug Type: Filesystem function related
Operating System: Linux
PHP Version: 5.2.6
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2008-08-08 10:58:14] 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 09:44:51] 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)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=45759&edit=1