Ask a Question related to PHP Notes, Design and Development.
-
didou@php.net #1
note 31567 deleted from function.feof by didou
Note Submitter:
----
Please note that this function "returns TRUE if [...] an error occurs". I don't quite understand why it does, but it means you must check every file pointer before using feof() inside a loop.
$fp = fopen($filename, 'r');
while (!feof($fp)) {
// ...
}
If the file doesn't exist, $fp, won't be a valid resource but feof() will retrun TRUE nonetheless, which means you will be caught in an endless loop.
$fp = fopen($filename, 'r');
if (!is_resource($fp)) {
// ...
} else {
while (!feof($fp)) {
// ...
}
}
Very annoying.
didou@php.net Guest
-
note 19929 deleted from function.is-a by didou
Note Submitter: php@electricsurfer.com ---- Here is a 3 line PHP implementation that worked for me: if (!function_exists('is_a')) {... -
note 21357 deleted from function.is-a by didou
Note Submitter: krisher@oswego.edu ---- Any implementation of is_a that relies on empty() to test whether the object parameter is empty will... -
note 19730 deleted from function.is-a by didou
Note Submitter: ernest@vogelsinger.at ---- For the previous example you need to exchange the function parameters to be compliant to the CVS... -
note 19727 deleted from function.is-a by didou
Note Submitter: dan at mojavelinux dot com ---- php implementation to keep us happy for now if (!function_exists('is_a')) { function... -
note 18743 deleted from function.defined by didou
Note Submitter: tac@smokescreen.org ---- use function_exists(string function_name) to check if a function has been defined.



Reply With Quote

