>>646
そういう内容ならクラス化してデストラクタに書けばいいんでないかい

class File{
 var $fp=null;
 function __construct($file,$mode='rb'){
  $this->fp=fopen($file,$mode);
  if(!$this->fp)
   throw new Exception('ファイルが開けなかった');
 }
 function __destruct(){
  if($this->fp)
   fclose($this->fp);
 }
}

try{
 $file=new File('test.txt');
}catch(Exception $e){
 echo $e;
}