try { include(''); } catch(e) { die('error'); } 

or

 @include ('') or die('error'); 

or

 if (file_exists('')) { include(''); } 

or

 $result = ('SELECT 1 FROM files WHERE file_name="" LIMIT 1'); if ($result) { include(''); } 
  • Good questions need to be encouraged! - Palmervan

1 answer 1

Correct. The dog does not eliminate the error, it only suppresses its output

And try-catch allows you not only to suppress, but also to take some specific measures. speed - very funny. If everything goes smoothly, this is the fastest way, except for just the bare code. When an error occurs - one of the slowest.

 <?php $time = microtime(true); for($i=0;$i<1000000;$i++){ @divByZero($i,0); } print((microtime(true)-$time).'<br />'); //1.66923713684 - делим на 0 //1.25963785172 - делим на 3 $time = microtime(true); for($i=0;$i<1000000;$i++){ try{ divByZeroE($i,0); }catch(Exception $e){ } } print((microtime(true)-$time).'<br />'); //5.61499404907 - делим на 0 //0.690489969254 - делим на 3 $time = microtime(true); for($i=0;$i<1000000;$i++){ divByZeroIfOnly($i,0); } print((microtime(true)-$time).'<br />'); //0.69531083107 - делим на 0 //0.69578036312 - делим на 3 function divByZero($a,$b){ return $a/$b; } function divByZeroE($a,$b){ if($b==0) throw new Exception('Division By Zero'); return $a/$b; } function divByZeroIfOnly($a,$b){ if($b==0) return false; return $a/$b; } 

now full? =)

  • Good answers too) - Palmervan
  • 3
    There is no Habr to write entire articles instead of answers! - Palmervan 1:51 pm
  • one
    Here are the results of the most difficult tests, beyond the mere mortals, respected @ good15 - knes