silexphp / Silex-WebProfiler

MIT License
210 stars 61 forks source link

Warning: strtr() expects parameter 1 to be string, object given error since upgrading to web-profiler:2.0.4 / symfony: 3.1.6 #102

Closed mantis closed 7 years ago

mantis commented 8 years ago

Receiving the following warning in the web profiler when hovering over the route:

Warning: strtr() expects parameter 1 to be string, object given in vendor\symfony\twig-bridge\Extension\CodeExtension.php on line 196 Call Stack

Time Memory Function Location

1 0.0006 388344 {main}( ) ...\index.php:0 2 0.0877 5119672 Mantis\Core->run( ) ...\index.php:182 3 0.1986 9529696 Silex\Application->run( ) ...\Core.php:35 4 0.1986 9529696 Silex\Application->handle( ) ...\Application.php:477 5 0.3761 12787256 Symfony\Component\HttpKernel\HttpKernel->handle( ) ...\Application.php:496 6 0.3761 12787560 Symfony\Component\HttpKernel\HttpKernel->handleRaw( ) ...\HttpKernel.php:68 7 0.4117 13373392 call_user_func_array:{vendor\symfony\http-kernel\HttpKernel.php:153} ( ) ...\HttpKernel.php:153 8 0.4118 13373696 Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController->toolbarAction( ) ...\HttpKernel.php:153 9 1.9679 20292744 Twig_Environment->render( ) ...\ProfilerController.php:195 10 2.0054 20235960 Twig_Template->render( ) ...\Environment.php:357 11 2.0054 20252392 Twig_Template->display( ) ...\Template.php:375 12 2.0056 20253256 Twig_Template->displayWithErrorHandling( ) ...\Template.php:364 13 2.0056 20253256 TwigTemplate_4f9cd5b720c1fb84a2c9cab7b3ef7bb5433aaecf4f8ee7e3056baf8d6e133607->doDisplay( ) ...\Template.php:396 14 2.0846 20451264 Twig_Template->getAttribute( ) ...\Environment.php(421) : eval()'d code:92 15 2.0847 20453288 Twig_Template->renderBlock( ) ...\Template.php:613 16 2.0847 20469768 Twig_Template->displayBlock( ) ...\Template.php:265 17 2.0847 20469768 TwigTemplate_870433559e9dd46960a9b7e5a8d747cd760b218e2e07a96cfdf63a915146833f->block_toolbar( ) ...\Template.php:203 18 2.0849 20489336 __TwigTemplate_870433559e9dd46960a9b7e5a8d747cd760b218e2e07a96cfdf63a915146833f->getset_handler( ) ...\Environment.php(421) : eval()'d code:49 19 2.0850 20507032 Symfony\Bridge\Twig\Extension\CodeExtension->getFileLink( ) ...\Environment.php(421) : eval()'d code:627 20 2.0851 20507384 strtr ( ) ...\CodeExtension.php:196

mamoot64 commented 7 years ago

Hi,

I confirm the bug. Here my composer.json :

    "require": {
        "php": ">=5.5.9",
        "silex/silex": "~2.0",
        "silex/web-profiler": "~2.0",
        "symfony/asset": "^3.1",
        "symfony/browser-kit": "~2.8|3.0.*",
        "symfony/class-loader": "~2.8|3.0.*",
        "symfony/config": "~2.8|3.0.*",
        "symfony/console": "~2.8|3.0.*",
        "symfony/css-selector": "~2.8|3.0.*",
        "symfony/debug": "~2.8|3.0.*",
        "symfony/finder": "~2.8|3.0.*",
        "symfony/form": "~2.8|3.0.*",
        "symfony/monolog-bridge": "~2.8|3.0.*",
        "symfony/process": "~2.8|3.0.*",
        "symfony/security": "~2.8|3.0.*",
        "symfony/translation": "~2.8|3.0.*",
        "symfony/twig-bridge": "~2.8|3.0.*",
        "symfony/validator": "~2.8|3.0.*",
        "symfony/http-kernel": "^3.1",
        "symfony/security-csrf": "^3.0",
        "doctrine/dbal": "~2.2",
        "symfony/var-dumper": "^3.0",
        "tijsverkoyen/css-to-inline-styles": "^1.5",
        "swiftmailer/swiftmailer": "^5.4",
        "guzzlehttp/guzzle": "^6.2",
        "tedivm/stash": "^0.14.1",
        "symfony/dom-crawler": "^3.1",
        "cocur/slugify": "^2.2"
    }

The problem (first approach) is on line 293 in WebProfilerServiceProvider.php :

$app['code.file_link_format'] = new FileLinkFormatter($app['code.file_link_format'], $app['request_stack'], $baseDir, '/_profiler/open?file=%f&line=%l#line%l');

On first call, $app['code.file_link_format'] is null, on second call, $app['code.file_link_format'] is a instance of FileLinkFormatter (i don't know why is called 2 times)

A Quick Fix is to test $app['code.file_link_format'] before instantiate FileLinkFormatter (is_object or instance_of).

Nicolas

fabpot commented 7 years ago

3.1 is not maintained anymore. Bumping to Symfony 3.2 fixes the issue though.