symfony: Symfony displays a blank page instead of an error page under certain circumstances
How to reproduce
- Create a controller action that contains
$foo->bar();. Make sure that$foois undefined. - Call said controller in both the
prodanddevenvironments.
Code sample
<?php
// src/Acme/BugReportBundle/Controller/BuggyController.php
namespace Acme\BugReportBundle\Controller;
class BuggyController
{
public function indexAction()
{
$foo->bar();
}
}
Attempt at analysis
When indexAction() is called, Symfony will display a blank page if Debug::enable() was called before (for example, if the dev environment is being used).
If you insert $foo = null; before $foo->bar();, then Symfony’s fatal error page will be displayed as intended.
Debug::enable() registers \Symfony\Component\Debug\ErrorHandler as an error handler. $foo->bar() will make PHP display two errors:
- Notice: Undefined variable: foo in file on line line
- Fatal error: Call to a member function bar() on a non-object in file on line line
The notice will trigger ErrorHandler::handle(), which will in turn raise a \Symfony\Component\Debug\Exception\ContextErrorException. However, presumably because of the fatal error in the same line, Symfony’s “Exception detected” page will not be displayed. The thrown ContextErrorException also prevents ErrorHandler::handleFatal() from being called (if the line that throws said exception is commented out, handleFatal() will be called and the error page is displayed properly). Because of this, a blank page will be displayed which is not really useful for debugging.
Other information
Operating system: Debian GNU/Linux 6.0.7 (Linux 2.6.32 i686) Symfony version: 2.3.3 PHP version: 5.3.6-11 (running via FastCGI)
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Reactions: 2
- Comments: 63 (26 by maintainers)
Commits related to this issue
- bug #9641 [Debug] Avoid notice from being "eaten" by fatal error. (fabpot) This PR was merged into the 2.3 branch. Discussion ---------- [Debug] Avoid notice from being "eaten" by fatal error. Wor... — committed to symfony/symfony by fabpot 11 years ago
- bug #11097 [Debug] simplify code path to remove potential blank pages (nicolas-grekas) This PR was merged into the 2.5 branch. Discussion ---------- [Debug] simplify code path to remove potential b... — committed to symfony/symfony by fabpot 10 years ago
- bug #11099 [Debug] work-around https://bugs.php.net/61272 (nicolas-grekas) This PR was merged into the 2.5 branch. Discussion ---------- [Debug] work-around https://bugs.php.net/61272 | Q ... — committed to symfony/symfony by fabpot 10 years ago
- bug #25408 [Debug] Fix catching fatal errors in case of nested error handlers (nicolas-grekas) This PR was merged into the 2.7 branch. Discussion ---------- [Debug] Fix catching fatal errors in cas... — committed to symfony/symfony by fabpot 7 years ago
I had some time today evening to create a test case for this bug.
php 7.1.8 symfony 3.3.6 any os
Steps to reproduce:
git clone --branch=bug-report/white-page-of-death https://github.com/d-ph/symfony-standard.gitcd symfony-standard\composer installphp bin\console server:runhttp://127.0.0.1:8000/. Confirm it returns a pretty error page with error:server:run(ctrl-c).vim app\AppKernel.phpnew \Sentry\SentryBundle\SentryBundle(),linephp bin\console server:runhttp://127.0.0.1:8000/Result: HTTP500 with white page of death.
Expected result: The same error page as in step 5.
More info: The issue is triggered after installing and enabling
sentry/sentry-symfony, but I doubt that the problem lies in that package. I believe any code trying to register an error handler withset_error_handlerAFTERSymfony\Component\Debug\ErrorHandlerwill trigger the problem. When it happens, then https://github.com/symfony/debug/blob/856a3e1/ErrorHandler.php#L563 :will no longer want to handle any errors, because the registered error handler is not
Symfony\Component\Debug\ErrorHandler.Xdebug screenshot, when I get the pretty error page:
Xdebug screenshot, when I get the white screen of death:
I bet there are at least a couple of ways to solve it, but none of them would be pretty. It’s just php things again.
@xabbuh Yeah I can see if I can replicate this outside my project hopefully either tonight or tomorrow. I’ll be happy to contribute! 😄
@ErvinSabic Can you open a new issue with a description on how we can reproduce your issue?
@fabpot This might have resurfaced.
Also on my homepage route ( / ), I am getting a Javascript console error that says Uncaught ReferenceError: Sfjs is not defined. It only does this on that route. The other pages are fine. Although I am not sure if these issues are related.
Dev machine specs / environment: OS: Linux Mint 18.2 “Sonya” Symfony Version: 3.4.9 Symfony Environment: Dev Apache Version: Apache/2.4.18 PHP Version: 7.2.4 Composer: version @package_branch_alias_version@ (1.0.0-beta2) 2016-03-27 16:00:34 (Holy crap) Mysql Version: 5.7.20-0ubuntu0.16.04.1
This is related to the fact, that
Symfony\Component\Debug\Debugdisables error reporting, when the request is not run from cli ini_set(‘display_errors’, 0);. This is supposed to be fine, because the Debug component is registering its own error handler. The problem is that (probably: some) PHP’s Fatal Errors immediately crash the script without running those custom error handlers, which leaves devs with the white page of death. One of those Fatal Errors is:(php 7.1.3, symfony 3.3.0 here)
(edit)
I couldn’t reproduce the problem with this particular error on fresh Symfony Standard project. Maybe I’ll fine some spare time later to isolate the cause of the problem from my current project.
Yes still happens in 3.3.2 too. Is there a new issue for this problem has this one is quit old ? But the first message is still relevant because it 's
Debug::enable();that leads to this weird behaviour. (+ other PHP error settings I suppose)False alarm (bug not fixed).
./bin/console cache:cleardid fix the issue with$foo->bar(). But the real error caused by$form->handleRequest($request);which ended up with the following fatal errorPHP Fatal error: Call to a member function add() on nullwas not shown by Symfony.Also note that display errors is on.
Symfony 3.1.2
php -v: PHP 5.6.11-1ubuntu3.4 (cli) Copyright © 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright © 1998-2015 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright © 1999-2015, by Zend Technologies with Xdebug v2.3.3, Copyright © 2002-2015, by Derick Rethans
uname -a 4.2.0-42-generic #49-Ubuntu SMP Tue Jun 28 21:26:26 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
The same problem also occurs in the current version of PHP, which is in actual debian repository.
Fortunately, I solved it by replacing the function. I write just for info, if anyone was looking for.
Original code colleague:
Repaired on: