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!!