How to debug php fatal errors in Silex Framework

蹲街弑〆低调 提交于 2019-12-04 09:39:48

问题


I wonder how can I see syntax errors like this (missing semicolon):

<?php
var_dump($app)
?>

This will cause a WSOD (white screen of death).

I tried to include a debug config file which look like this:

use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\Debug\Debug;

// Include the prod configuration
require __DIR__.'/prod.php';

// Enable PHP Error level
error_reporting(E_ALL);
ini_set('display_errors','On');

// Enable debug mode
$app['debug'] = true;

// Handle fatal errors
ErrorHandler::register();

Debug::enable();

I included in composer json file:

"symfony/debug": "~2.3",

But still no change. What did I forgot?


回答1:


Try this:

use Symfony\Component\HttpKernel\Debug\ErrorHandler;
use Symfony\Component\HttpKernel\Debug\ExceptionHandler;

// set the error handling
ini_set('display_errors', 1);
error_reporting(-1);
ErrorHandler::register();
if ('cli' !== php_sapi_name()) {
  ExceptionHandler::register();
}

// init application
$app = new Silex\Application();

// set debug mode
$app['debug'] = true

$app->run();

it's important to set the error handling before initialize the $app.




回答2:


Install Symfony/debug using composer require symfony/debug and add these lines before Silex\Application instance

use \Symfony\Component\Debug\ErrorHandler;
use \Symfony\Component\Debug\ExceptionHandler;
ini_set('display_errors', 0);
error_reporting(-1);
ErrorHandler::register();
ExceptionHandler::register();


来源:https://stackoverflow.com/questions/23315742/how-to-debug-php-fatal-errors-in-silex-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!