@ error suppressor

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: @ error suppressor

Post 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.
M2tM
Forum Commoner
Posts: 41
Joined: Sat Feb 27, 2010 12:35 pm

Re: @ error suppressor

Post 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?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: @ error suppressor

Post 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.
M2tM
Forum Commoner
Posts: 41
Joined: Sat Feb 27, 2010 12:35 pm

Re: @ error suppressor

Post 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;
        }
    }
 
Post Reply