8000 [2.2][HttpKernel] ErrorHandler suppresses E_NOTICE error ending up with blank page in dev. · Issue #7499 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[2.2][HttpKernel] ErrorHandler suppresses E_NOTICE error ending up with blank page in dev. #7499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
groucho-zz opened this issue Mar 27, 2013 · 14 comments

Comments

@groucho-zz
Copy link

The php error :
PHP Fatal error: Call to a member function getRepository() on a non-object

is suppressed and a blank page is rendered despite being in dev ( app_dev.php )

To replicate:
remove $em = $this->getDoctrine()->getManager(); from any crud action.

@xaben
Copy link
xaben commented Apr 12, 2013

The error you show here is a PHP Fatal error, which is handled by PHP and can't be caught during runtime, also app_dev.php doesn't guarantee the display of the error. It's up to you to set the diplay_errors and error_reporting in php.ini for your development environment (http://php.net/manual/en/errorfunc.configuration.php). By default php errors are logged.

There is a PR that will add Fatal error logging to the application logs, until then php logs are the way to go.

Take a look at these:
#6474
#2042

@groucho-zz
Copy link
Author

@xaben i have error display turned on in php
the problem is that symfony does not seem to handle
catching the error properly, hence the blank page.

but thanks for the references

@fabpot
Copy link
Member
fabpot commented Apr 21, 2013

There is something else going on. I've just tried with the Symfony Standard Edition 2.2, and Symfony catches fatal errors and notices in the dev env.

@groucho-zz
Copy link
Author

@fabpot
i have just re-tried with a fresh project. on 2.2.1.

  • created crud,
  • commented $em = $this->getDoctrine()->getManager();
  • from the browser, i get a blank page
  • from the php logs, the error is logged
    PHP Fatal error: Call to a member function getRepository() on a non-object in [removed-base-path]Bundle/Controller/PageController.php on line 10
  • tried to add a random $em->getRepository() in a test php file and the error
    is displayed properly in the browser ( in dev environment ) as displayed in logs
  • tried to add a random $em->getRepository() in an old Symfony 1.4 project and the error
    is displayed properly in the browser ( in dev environment ) as displayed in logs

I am not well-versed enough to trace figure it out through symfony 2's internals
but it seems line 61 of Symfony\Component\Debug\ErrorHandler.php :
ini_set('display_errors', 0);
affects the display.

@Koc
Copy link
Contributor
Koc commented Apr 25, 2013

I can confirm this issue. One of my employeers got same problem. Looks like problem was introduced in one of theese commits: cb319ac, 5d98fb1

@Koc
Copy link
Contributor
Koc commented Apr 25, 2013

Also looks like it depends of php sapi (mod_apache).

@Koc
Copy link
Contributor
Koc commented Apr 27, 2013

It does not depends on php sapi. When ErrorHandler throw exception it doesn't catching by ExceptionHandler or HttpKernel. I don't know what going, but shutdown function not called in this case.

@VanTanev
Copy link
VanTanev commented May 2, 2013

Confirming this issue with nginx + php_fpm. A fatal error will be outputted to nginx's error log:

2013/05/02 21:47:39 [error] 14225#0: *24 FastCGI sent in stderr: "PHP message: PHP Fatal error:[...]

but nginx will display 502 Bad Gateway. Removing the ini_set('display_errors', 0); line from ErrorHandler.php will allow the error to be displayed again.

Between having an error be outputted twice and a blank page being displayed, I will take the double output every time.

@VanTanev
Copy link
VanTanev commented May 3, 2013

Just a note, the way I replicated this issue:

<?php

namespace Blogger\BlogBundle\Entity;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints;

class Enquiry
{
    public static function loadValidatorMetadata(ClassMetadata $metadata)
    {
        # Class MaxLength replaced by Length in sf 2.3 -> fatal error class does not exist
        $metadata->addPropertyConstraint('name', new Constraints\MaxLength(50));
        [...]

@yjv
Copy link
yjv commented Jun 3, 2013

It looks like this happens when both a notice and fatal happen at once if both the variable you're calling the method on is not defined (which throws a notice) and then the method as well is not defined (obviously:)) which throws a fatal for some reason everything just shuts down instead of processing both.

@groucho-zz
Copy link
Author

I guess this is fixed in 2.3 #6474

@Koc
Copy link
Contributor
Koc commented Jun 5, 2013

no, it isn't fixed by this commits

@srosato
Copy link
srosato commented Jun 17, 2013

I can confirm this:

composer.phar create-project symfony/framework-standard-edition symfony-standard 2.3.1

edit WelcomeController within indexAction() and add:

$foo = null;
$foo->getBar();

This will display the fatal error correctly. Now remove the $foo = null so we just have

$foo->getBar();

This would trigger both a notice for the undefined variable and an error for the call to a member on the non-object, but instead a blank page is displayed, unless something is wrong for my apache's php.ini development configuration settings.

php.ini:

error_reporting = E_ALL | E_STRICT
display_errors = On

but that does not seem to matter since error_reporting is set to -1 and display_errors set to 0.

@fabpot
Copy link
Member
fabpot commented Aug 22, 2013

Looks like a duplicate of #8703 in which case this is a PHP bug. Feel free to reopen is the bug is different.

@fabpot fabpot closed this as completed Aug 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants
0