Symfony2: __toString() must not throw an exception - symfony

I am deploying my Symfony2 application, but I am getting the following error:
FatalErrorException in classes.php line 0:
Error: Method Symfony\Component\HttpFoundation\Request::__toString() must not throw an exception
Apache is slightly more descriptive, stating something about Monolog:
PHP Fatal error: Method Symfony\\Component\\HttpFoundation\\Request::__toString() must not throw an exception in /my/path/vendor/monolog/monolog/src/Monolog/Formatter/NormalizerFormatter.php on line 0
It is also the only thing It is not clear to me how this is happening. Dev-environment on my local machine is running fine.
I have tried to clear the prod cache, the composer cache and restarted apache service. I also did a fresh "composer install" after clearing its cache.
Anyone has an idea how this can be solved? Am running Symfony v2.7.4.

You should to check your $_COOKIE or $_SESSION for example;
The trouble is you could have array value in $_COOKIE, so on your debug environment you could fall into the following situation:
Debug::enable() //see, i don't exclude E_NOTICE here
$request = Request::createFromGlobals();
echo $request->__toString();
//so, from now you've got your Exception because of
//Debug package converts E_NOTICE to Fatal
//which turns into Exception
So if you want to fix this trouble you need to:
find the real reason of exception triggering (notice, deprecated, strict message, etc)
exclude it from Debug: Debug::enable(~E_NOTICE);
OR just remove (string)$request from your code if possible;
see Request code:
//part of __toString() method
foreach ($this->cookies as $k => $v) {
$cookies[] = $k.'='.$v;
}

Related

Error 500 after composer update in symfony 3

i try to clone my project into my computer.
I had clone the repository and done "composer update". All without any errors.
when i try to visit my site show this error
Call to a member function has() on null
500 Internal Server Error - FatalThrowableError
and the debug
CRITICAL - Call to a member function has() on null
CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Call to a member function has() on null" at C:\xampp\htdocs\richiesta_analisi\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Controller\Controller.php line 234
is the same repository that i had in remote so i don't understand why don't work.
i tryed to clear cache and composer upgrade but nothing.
Can you help me?

JMS Call to a member function has() on null

Bundle version 1.3.1
| Symfony version 3.3
| PHP version 7.1.9
Expected behavior
After installing the different bundles (JMSTranslationBundle, JMSDIExtraBundle, checking if i had sensio/framework-extra-bundle), and after i made the right configuration in config.yml and routing_dev.yml, the right behavior should be that the /_trans lead me to a translation interface (working), and change nothing else.
Actual behavior
Getting on a route different from /_trans return Call to a member function has() on null with error 500. Therefore, the whole site is dead, except the translation UI.
Steps to reproduce
Install JMSTranslationBundle, then when asked, install JMSDIExtraBundle to get the web ui
After that, test the /_trans. This should work. But when you get to your others routes, they return 500 error
I have exactly the same issue (Sf 3.3.9/PHP 7.1.9). I have to remove the line related to "JMSDiExtraBundle" in AppKernel to make my app works again. This is the only workaround I found, not very efficient.
Very low trace log information, this is what I have:
Stack Trace:
Logs:
CRITICAL 19:56:59 php Call to a member function has() on null
CRITICAL 19:56:59 request Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Call to a member function has() on null" at /Users/stephanfo/PhpstormProjects/openbuy/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php line 233
Exception:
Any help would be helpful.
Thanks,
Stef.

Sylius template rendering exception - channel not found

I just installed a copy of Sylius on my dev server (Ubuntu), configured the database parameters, resolved all dependencies, and ran sylius:install. Install completed successfully, and all looked good.
When trying to access the front-end (web/app_dev.php), however, I get an error thrown during template rendering:
Uncaught PHP Exception Twig_Error_Runtime: "An exception has been
thrown during the rendering of a template ("Channel could not be
found!") in "SyliusWebBundle:Frontend:layout.html.twig" at line 55."
at
/var/www/mysite.com/public_html/vendor/twig/twig/lib/Twig/Template.php
line 182 Context: { "exception": "Object(Twig_Error_Runtime)" }
I'm not entirely sure what channel it's unable to find, or how to resolve this.

symfony 2.8 debug fatal error double message

Environment: Symfony 2.8.1 with XAMPP Version 5.5.24 on Windows 7.
If I trigger a fatal error in a controller, anything as simple as $array = ; in production environment, I'm getting a default php error:
Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\tgsupport-test\src\AppBundle\Controller\DefaultController.php on line 16
followed by symfony custom error page message. Obviously I'd want to avoid to show eorr info in production.
Moreover in prod.log I see a double critical error: under php.CRITICAL and request.CRITICAL. Is really useful to show the same error twice?
I'm using default configuration, indeed I just installed default framework without any custom setting and I triggered my error in AppBundle/DefaultController, so I was wondering if I'm missing anything.
I missed a php.ini configuration to avoid to display error messages in page.

json_encode work from command line but does't work with nginx

I have php5.5, nginx installed on Ubuntu 13.10 of Ec2.
My error relate to json_encode function :
PHP Fatal error: Call to undefined function json_encode()
After reading PHP Fatal error: Call to undefined function json_decode(), i install php5-json. As result, it works well when i call json_encode from command line.
But it doesn't work if i call json_encode from nginx server. I tried to add extension=json.so to the files /etc/php5/cli/php.ini and /etc/php5/fpm/php.init. But it can't resolve the problem.
Could you help me ?
Thank you in advance
Just to begin :
You uncomment
extension=json.so in
/usr/local/php5/etc/extensions.ini ?
And did you restart php5-fpm ?
Else, could you give us your phpinfos() ? (section json)

Resources