Pagina 1 di 1

[Risolto]dopo un E_NOTICE interrompe l'esecuzione dello s...

Inviato: sabato 21 maggio 2016, 7:29
da TommyB1992
L'errore viene generato da una variabile non definita inserita appositamente, non viene stampato "eddai stampati",

Codice: Seleziona tutto

  protected function __blindInitSession() {
    //parent::$sessObj = new adminSession;
    echo $a;
    die('eddai stampati');
  }
L'error handler e l'exception handler sono settati così:

Codice: Seleziona tutto

    final static public function exceptionHandler(\Exception $e) {
        try {
            if ($e instanceof IException) {
              $e->show();
            }
        }
        catch (\Exception $exception) {
            die(
        "<pre>BlindCore::exceptionHandler() Unhandled exception: ".
          BaseErrorHandler::hideCriticalInfo(Security::htmlspecialchars($exception->getMessage()))."\n\n".
          BaseErrorHandler::hideCriticalInfo(Security::htmlspecialchars($exception->getTraceAsString()))
      );
        }
    }
 
  final static public function errorHandler($errorNo, $message, $filename, $lineNo) {
        if (error_reporting() != 0) {
          throw new BlindException('PHP error in file '.$filename.' ('.$lineNo.'): '.$message, $errorNo);
        }
  }
E questo è il metodo con il quale stampo l'errore, nonostante non ci sia nesun exit e die, perchè l'error code è di tipo E_NOTICE, perciò dovrebbe proseguire tranquillamente l'esecuzione dello script.

Codice: Seleziona tutto

  public function show() {
    if (!in_array($this->_code, array(E_NOTICE, E_DEPRECATED))) {
      header('Expires: Mon, 21 Jul 1992 05:00:00 GMT');
      header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
      header('Cache-Control: no-cache');
      header('Pragma: no-cache');
      header('HTTP/1.1 503 Service Temporarily Unavailable');
      header('Status: 503 Service Temporarily Unavailable');
      header('Retry-After: 3600');
      header('Content-Type: text/html; charset=utf-8');

      if (DEVELOPMENT || $this->_type == 'custom') $errorMsg = $this->_message;
      else {
        $errorMsg = 'Do not worry. Retry again';
      }
 
      die(
        '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n".
        '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">'."\n".
        '<head>'."\n".
        '<title>Error</title>'."\n".
        '</head>'."\n".
        '<body style="margin: 40px; font: 85%/130% verdana, arial, sans-serif; color: #333;">'."\n".
        '<h1>An error was encountered</h1>'."\n".
        '<hr />'."\n".
        '<p>'.$errorMsg.'</p>'."\n".
        '</body>'."\n".
        '</html>'."\n"
      );
    }
  }
Come mai?

Re: PHP - Dopo un E_NOTICE interrompe l'esecuzione dello scr

Inviato: domenica 22 maggio 2016, 0:17
da Zoff
Il tuo errorHandler trasforma TUTTI gli eventi in eccezioni (usi throw). Le eccezioni sono bloccanti.

Se sostituisci:

Codice: Seleziona tutto

throw new \Exception('PHP error in file '.$filename.' ('.$lineNo.'): '.$message, $errorNo);
con:

Codice: Seleziona tutto

exceptionHandler(new \Exception('PHP error in file '.$filename.' ('.$lineNo.'): '.$message, $errorNo));
Vedrai che l'esecuzione procede.

Re: PHP - Dopo un E_NOTICE interrompe l'esecuzione dello scr

Inviato: domenica 22 maggio 2016, 3:19
da TommyB1992
grazie, sei veramente preparato.