symfony / symfony

The Symfony PHP framework
https://symfony.com
MIT License
29.84k stars 9.48k forks source link

FlattenException class not found. #10313

Closed filipgorny closed 10 years ago

filipgorny commented 10 years ago

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 commented 10 years ago

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

fabpot commented 10 years ago

Closing as there is no feedback.

radekz2 commented 10 years ago

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 commented 10 years ago

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

radekz2 commented 10 years ago

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

nicolas-grekas commented 10 years ago

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 commented 10 years ago

How do I get that version number?

stof commented 10 years ago

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

radekz2 commented 10 years ago

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 commented 10 years ago

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 https://github.com/symfony/symfony/pull/10817

radekz2 commented 10 years ago

Ok great thanks!

nicolas-grekas commented 10 years ago

@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 commented 10 years ago

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!