php - Proper way to handle unavoidable warnings -


there're many old procedural functions can emit warnings due error conditions happen on regular operation, e.g.: fopen(), mail(), oci_connect()...

  • the most obvious workaround said expensive , has side effect of hiding everything:

    echo @file_get_contents(oops_forgot_dollar); 
  • a custom error handler looks overkill:

    private function warninghandler($errno, $errstr, $errfile, $errline/*, array $errcontext*/){     if(error_reporting()===0){         return false;     }else{         throw new errorexception($errstr, 0, $errno, $errfile, $errline);     } }  // ....  try{     set_error_handler('csvloader::warninghandler', e_warning);     $this->fp = fopen($filename, 'r');     restore_error_handler();      $this->readdata(); }catch(errorexception $e){     restore_error_handler();     throw new csvloaderexception("could not open file: {$e->getmessage()}"); } 
  • letting warning pass through annoying in configured server:

    • in developement display in middle of , can break things
    • in production flood error log useless data

what's recommended practice? how php gurus handle it?

the error_log not useless data

i find it's easy enough keep on top of if there's hourly cron job emails contents of error_log file .....

soon you'll have added in appropriate checks code base , problems sorted.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -