FlattenException class not found. #10313

Closed
filipgorny opened this Issue Feb 22, 2014 · 13 comments

6 participants

@filipgorny

I have some weird issue with FlattenException. I tried to fix it myself but after few hours of thinking what can be wrong I didn't come to anything.

What I found out is that the FlattenException create method is called, with ClassNotFound exception as the first argument, with message that the FlattenException class is not found.

It sounds like a non-sense.

Actually I know what is wrong in my business logic code. I have a class that has incompatible method declaration with the parent class. I know it because I printed the exception stack in ExceptionHandler::createResponse. Then there is FlattenException::create method called which causes ClassNotFoundException, even it actually go into the create method.

The error message is

ClassNotFoundException: Attempted to load class "FlattenException" from namespace "Symfony\Component\Debug\Exception" in /var/www/grocery/src/Potato/LocationBundle/Adapter/LocationEntity.php line 0. Do you need to "use" it from another namespace? Perhaps you need to add a use statement for one of the following: Symfony\Component\HttpKernel\Exception\FlattenException, Symfony\Component\Debug\Exception\FlattenException.

LocationEntity.php on line 0?

It is not a true of course.

When I comment out the FlattenException::create line, then Symfony doesn't print anything.

I tried to find the reason and fix it myself but I gave up. It may be even a PHP bug.

@jakzal jakzal added the Debug label Feb 22, 2014
@jakzal
Symfony member

Would you mind to reproduce your issue on a fork of Standard Edition? Would help us to debug.

@fabpot
Symfony member

Closing as there is no feedback.

@fabpot fabpot closed this Apr 28, 2014
@radekz2

Just run into this same exception after adding a form to my controller:

ClassNotFoundException: Attempted to load class "FlattenException" from namespace "Symfony\Component\Debug\Exception" in /vagrant/src/Rgrs/ContestBundle/Controller/DefaultController.php line 28. Do you need to "use" it from another namespace? Perhaps you need to add a use statement for one of the following: Symfony\Component\Debug\Exception\FlattenException, Symfony\Component\HttpKernel\Exception\FlattenException.

Here's the controller:

<?php

namespace Rgrs\ContestBundle\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

/**
 *  @Route("/")
 */
class DefaultController extends BaseController
{
    /**
    * @Route("", name="homepage_action")
    * @Method({"GET"})
    */
    public function indexAction(Request $request)
    {
        $entity = new \Rgrs\ContestBundle\Entity\ContestEntryGCaptcha();
        $contestForm = $this->createForm(new \Rgrs\ContestBundle\Form\ContestEntryGCaptchaForm(), $entity);
        $contestForm->handleRequest($request);

        return $this->render('RgrsContestBundle:Default:index.html.twig', array("form" => $contestForm->createView()));
    }
}

Symfony version 2.4.4

Update:

Not extending BaseController (my code) by switching to Controller fixed it.

@jakzal jakzal reopened this Apr 28, 2014
@jakzal
Symfony member

@radekz2 would you mind forking Symfony Standard Edition and recreating this issue on a branch? Controller alone is not enough to reproduce.

@radekz2

Not a problem, will update this as soon as I have some results, may take me couple of days.

@nicolas-grekas

Which version of the debug component do you have?
I suspect you're hit by https://bugs.php.net/42098
Version 2.5 should have a proper workaround, tell me if it works with you.

@radekz2

How do I get that version number?

@stof
Symfony member

composer show -i will show you the versions of all packages installed through composer

@radekz2

Here's what I see

doctrine/annotations                 v1.1.2             Docblock Annotations Parser
doctrine/cache                       v1.3.0             Caching library offering an object-oriented API for many cache backends
doctrine/collections                 v1.2               Collections Abstraction library
doctrine/common                      v2.4.1             Common Library for Doctrine projects
doctrine/dbal                        v2.4.2             Database Abstraction Layer
doctrine/doctrine-bundle             v1.2.0             Symfony DoctrineBundle
doctrine/inflector                   v1.0               Common String Manipulations with regard to casing and singular/plural rules.
doctrine/lexer                       v1.0               Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/orm                         v2.4.2             Object-Relational-Mapper for PHP
excelwebzone/recaptcha-bundle        dev-master d08f803 This bundle provides easy reCAPTCHA form field integration
gregwar/captcha                      v1.0.11            Captcha generator
gregwar/captcha-bundle               dev-master 7c38520 Captcha bundle
incenteev/composer-parameter-handler v2.1.0             Composer script handling your ignored parameter file
jdorn/sql-formatter                  v1.2.17            a PHP SQL highlighting library
kriswallsmith/assetic                v1.1.2             Asset Management for PHP
monolog/monolog                      1.9.1              Sends your logs to files, sockets, inboxes, databases and various web services
psr/log                              1.0.0              Common interface for logging libraries
sensio/distribution-bundle           v2.3.4             The base bundle for the Symfony Distributions
sensio/framework-extra-bundle        v3.0.0             This bundle provides a way to configure your controllers with annotations
sensio/generator-bundle              v2.3.4             This bundle generates code for you
swiftmailer/swiftmailer              v5.1.0             Swiftmailer, free feature-rich PHP mailer
symfony/assetic-bundle               v2.3.0             Integrates Assetic into Symfony2
symfony/icu                          v1.2.1             Contains an excerpt of the ICU data and classes to load it.
symfony/monolog-bundle               v2.5.1             Symfony MonologBundle
symfony/swiftmailer-bundle           v2.3.7             Symfony SwiftmailerBundle
symfony/symfony                      v2.4.4             The Symfony PHP framework
twig/extensions                      v1.0.1             Common additional features for Twig that do not directly belong in core
twig/twig                            v1.15.1            Twig, the flexible, fast, and secure template language for PHP
@stof
Symfony member

symfony/symfony v2.4.4 means you have the 2.4.4 version of the Debug component (which is a subpart of the fullstack framework).
@nicolas-grekas opened a PR to fix the issue in 2.3 (which will be applied to 2.4 after the merge) in #10817

@radekz2

Ok great thanks!

@fabpot fabpot added a commit that referenced this issue Apr 30, 2014
@fabpot fabpot bug #10817 [Debug] fix #10313: FlattenException not found (nicolas-gr…
…ekas)

This PR was merged into the 2.3 branch.

Discussion
----------

[Debug] fix #10313: FlattenException not found

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10313
| License       | MIT
| Doc PR        | none

Note that this patch should be ignored while merging into 2.5/master (it will conflict because 2.5/master has a much stronger workaround, not suitable for a minor release IMHO).

Commits
-------

b147cfa [Debug] fix #10313: FlattenException not found because of https://bugs.php.net/42098
c18bf19
@fabpot fabpot added a commit that referenced this issue Apr 30, 2014
@fabpot fabpot Merge branch '2.3' into 2.4
* 2.3:
  [Debug] fix #10313: FlattenException not found because of https://bugs.php.net/42098
2724903
@fabpot fabpot closed this Apr 30, 2014
@fabpot fabpot added a commit that referenced this issue Apr 30, 2014
@fabpot fabpot Merge branch '2.4'
* 2.4:
  [Debug] fix #10313: FlattenException not found because of https://bugs.php.net/42098
49bc4f1
@fabpot fabpot added a commit that referenced this issue Apr 30, 2014
@fabpot fabpot Revert "bug #10817 [Debug] fix #10313: FlattenException not found (ni…
…colas-grekas)"

reverted in 2.5 as it does not make sense here.

This reverts commit c18bf19, reversing
changes made to 585b61d.
afca3cd
@nicolas-grekas

@radekz2 can you please confirm that the proposed patch fixes the issue?
The easiest way to do that might be to replace your vendor/symfony/symfony/src/Symfony/Component/Debug/ErrorHandler.php file with https://raw.githubusercontent.com/nicolas-grekas/symfony/b147cfaf15492660d6d878d6815512943446401b/src/Symfony/Component/Debug/ErrorHandler.php

@radekz2

I've copied the file and got a proper exception that helped me fix the actual code issue.

Applying this patch fixes the issue.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment