Skip to content
This repository has been archived by the owner on Sep 14, 2018. It is now read-only.

Warning: strtr() expects parameter 1 to be string, object given #75

Open
Kingyo opened this issue Dec 3, 2016 · 5 comments
Open

Warning: strtr() expects parameter 1 to be string, object given #75

Kingyo opened this issue Dec 3, 2016 · 5 comments

Comments

@Kingyo
Copy link

Kingyo commented Dec 3, 2016

Hi,

I've downloaded the skeleton and when I go on the index, I have this error:
[2016-12-03 18:16:20] app.CRITICAL: Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("Warning: strtr() expects parameter 1 to be string, object given") in "@WebProfiler/Collector/request.html.twig" at line 271. (uncaught exception) at C:\wamp\www\sv\vendor\twig\twig\lib\Twig\Template.php line 222 {"exception":"[object] (Twig_Error_Runtime(code: 0): An exception has been thrown during the rendering of a template (\"Warning: strtr() expects parameter 1 to be string, object given\") in \"@WebProfiler/Collector/request.html.twig\" at line 271. at C:\\wamp\\www\\sv\\vendor\\twig\\twig\\lib\\Twig\\Template.php:222, Symfony\\Component\\Debug\\Exception\\ContextErrorException(code: 0): Warning: strtr() expects parameter 1 to be string, object given at C:\\wamp\\www\\sv\\vendor\\symfony\\twig-bridge\\Extension\\CodeExtension.php:197)"} []

I am on Windows 10, php 7.x
Do you have any idea how to fix it please?

Thanks.

@gitruslan
Copy link

gitruslan commented Dec 8, 2016

HI,
I've got same issue, after quick researching and debugging , i found what kind of problem is causing this error .

file -  vendor/symfony/web-profiler-bundle/Resources/views/Collector/request.html.twig 
line (271)- {%- set link = controller.file|file_link(controller.line) %} 

and hence
filter function getFileLink

file - vendor/symfony/twig-bridge/Extension/CodeExtension.php
line (196) - strtr($this->fileLinkFormat, array('%f' => $file, '%l' => $line)); 

cached call

  $context["link"] = $this->env->getExtension('Symfony\Bridge\Twig\Extension\CodeExtension')
                    ->getFileLink($this->getAttribute(($context["controller"] ?? $this->getContext($context, "controller")), "file", array()), $this->getAttribute(($context["controller"] ?? $this->getContext($context, "controller")), "line", array()));

$this->fileLinkFormat here is object Symfony\Component\HttpKernel\Debug\FileLinkFormatter
and of course strtr doesnt understand it.

I debugged same code with symfony 2.8
$this->fileLinkFormat was null, function returned false and everything was ok.

But if call this function separately outside block {% macro set_handler.....
{{'real/path'|file_link(12) }}
You will not get any errors.

You can solve temporary this problem by comment this piece of code
file_link(controller.line) - in request.html.twig
or

  //return strtr($this->fileLinkFormat, array('%f' => $file, '%l' => $line));
  return $this->fileLinkFormat->format($file, $line);
in CodeExtension.php

@iBet7o
Copy link

iBet7o commented Dec 14, 2016

same problem

@stefanospetrakis
Copy link

+1

@allejo
Copy link

allejo commented Dec 29, 2016

Same issue here, seems like 3.2 for twig-bridge has changed the way this is handled and fixes the issue.

@TheCelavi
Copy link

Changed in composer.json to

"symfony/twig-bridge": "~3.2",

All works fine. Someone should create a PR...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants