note 60632 added to function.feof
| From: | docey at osu1 dot php dot net | Date: | Thu, 12 Jan 2006 19:07:24 +0000 |
| Subject: | note 60632 added to function.feof | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101650@lists.php.net to get a copy of this message | ||
because using an invalid handle can couse seriuos trouble,
here is some very simple code that can prevent any piece
of code to runaway using an invalid handle.
function is_valid(&$fp, $type){
if(is_resource($fp)){
if(get_resource_type($fp) == $type){
return true;
}else{
return false;
}
}else{
return false;
}
}
now all you need to do to check if you got a valid handle,
if(is_valid($fp, "file")){
// your code
}else{
// your error code
}
its that simple to prevent any of your code from using an
invalid handle. ofcourse you can change the "file" line to
any resource you want to check for invalidies.
please use good coding habits, and don't assume any
varialbles, resource or objects are good. check them!!
----
Manual Page -- http://www.php.net/manual/en/function.feof.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60632
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60632&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60632&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60632&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60632&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60632&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60632&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60632&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60632&report=yes
Search -- http://master.php.net/manage/user-notes.php