Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Symfony displays a blank page instead of an error page under certain circumstances #8703

Closed
@C3rise

Description

@C3rise

How to reproduce

  1. Create a controller action that contains $foo->bar();. Make sure that $foo is undefined.
  2. Call said controller in both the prod and dev environments.

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:

  1. Notice: Undefined variable: foo in file on line line
  2. 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)

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions