Page 2 of 2

Re: @ error suppressor

Posted: Tue Mar 16, 2010 8:09 pm
by Weirdan
Darhazer wrote:If you suppress error/warning of mysql_connect and the mysql extension is not enabled, you'll get a fatal error (call to undefined function) which results in a blank screen.
In fact it results in 500 Internal Server Error handled by the webserver (showing generic 'Whoops, we're sorry' message) on any correctly configured webserver. Checking for extension availability is either done during installation or before calling mysql_connect(). I was taking it for granted you checked that the function was available before calling it. However checking that the domain name resolves, host is reachable, port is open and there's something speaking MySQL protocol prior to connecting sounds like an overkill to me. In my opinion it should be discretely reported by the API to the calling code and logged only if the calling code does not handle it.

Re: @ error suppressor

Posted: Thu Mar 18, 2010 4:31 pm
by M2tM
How about in cases where you are generating a buffer using ob_start etc and you don't want to corrupt the buffer with error messages? Or in situations where you want to detect the error but output your own message and formatting?

Re: @ error suppressor

Posted: Thu Mar 18, 2010 4:40 pm
by Benjamin
M2tM wrote:How about in cases where you are generating a buffer using ob_start etc and you don't want to corrupt the buffer with error messages? Or in situations where you want to detect the error but output your own message and formatting?
You have the ability to change error handlers, reporting levels and the display errors settings on the fly. You can do what you wish with errors as you desire.

Re: @ error suppressor

Posted: Mon Mar 22, 2010 3:26 am
by M2tM
Yeah, what I mean is, if you are already generating a solid error message with a callstack included it seems redundant to then also store the php generated message with less information (not always, it depends on the function being called.) Sometimes if I'm handling the error myself I will use error suppression on the function I'm calling... But of course outputting the errors to a log makes a lot of sense and that's what I have in 99% of cases.

Code: Select all

 
    function mv_errorOutput($text, $return = false){
        $location = debug_backtrace();
        $locationCount = min(count($location), MV_MAX_CALLSTACK_SIZE);
        $hiddenOutput = '<!--[if !IE>'."\n";
        for($i = 0;$i < $locationCount;$i++){
            $hiddenOutput.= '    '.$location[$i]['file'].':('.$location[$i]['line'].') => '.$location[$i]['function']."\n";
        }
        $hiddenOutput.= '__________________'."\n".'<![endif]-->'."\n";
        
        $output= "\n".'<div style = "color:red;background-color:black;text-align:center;">'."\n".
                 $hiddenOutput.
                 $text.
                 "\n".'</div>'."\n";
        if($return){
            return $output;
        }else{
            echo $output;
        }
    }