简体   繁体   中英

Errors inside of output buffer

I'm having some problems with the output buffer. I am buffering my script and printing the result using a callback. The problem is that if a error is thrown at any point, nothing is being shown and I am getting a blank screen. I have tried setting my own custom error handlers but nothing seems to work. I have a feeling this is because the errors are causing my buffer to call the callback method instead of my error handler. Either that or it's because I have the error handler as a static method, but changing that causes issues elsewhere.

I'd really appreciate any help because this one has me stumped!

public function constructor()
{
    ob_start(array(__CLASS__, 'render'));
    self::$buffer_level = ob_get_level();

    set_error_handler(array(__CLASS__, 'exception_handler'));
    set_exception_handler(array(_C_LASS__, 'exception_handler'));

    RUNNING MY SCRIPT HERE

    ob_end_flush();
}

public static function exception_handler($exception, $message = NULL, $file = NULL, $line = NULL)
{
    while (ob_get_level() > self::$buffer_level)
    {
    ob_end_clean();
    }

    echo $exception.' - '.$message.' - '.$file.' - '.$line.'<br/>';
}  
_C_LASS__

看起来您放错了_

Damn, that is actually a typo which isn't in the script, so that isn't what is causing the problem. Good spot though!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM