<p dir="auto">Today I'm update a version of the Symfony using<br>
$&gt;bin/vendors update</p>
<p dir="auto">After the update, I need clear the cache, but I found this error.</p>
<p dir="auto">$&gt;php app\console cache:clear</p>
<p dir="auto">Catchable fatal error: Object of class Symfony\Component\ClassLoader\DebugUniversalClassLoader could not be converted to string in E:\Projetos\eMarketing\vendor\symfony\src\Symfony\Component\ClassLoader\DebugUniversalClassLoader.php on line 42</p>
<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>yes</td>
</tr>
<tr>
<td>Feature request?</td>
<td>no</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>no</td>
</tr>
<tr>
<td>RFC?</td>
<td>no</td>
</tr>
<tr>
<td>Symfony version</td>
<td>4.0.3</td>
</tr>
</tbody>
</table>
<p dir="auto">TL;DR; <code class="notranslate">Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinder</code> doesn't find templates inside the <code class="notranslate">templates/</code> folder.</p>
<p dir="auto">This is because the <code class="notranslate">TemplateFinder</code> is unaware of the <code class="notranslate">paths</code> setting in the <code class="notranslate">twig</code> config. Changing the default directory structure in Symfony 4 means this setting is used more often now.</p>
<p dir="auto">Related issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="197391187" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/21035" data-hovercard-type="pull_request" data-hovercard-url="/symfony/symfony/pull/21035/hovercard" href="https://github.com/symfony/symfony/pull/21035">#21035</a><br>
Example usage in the wild: <a href="https://github.com/hostnet/webpack-bundle/blob/master/src/Component/Asset/Tracker.php#L187-L189">Tracker</a></p>
<p dir="auto">Steps to reproduce:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="composer create-project symfony/skeleton my_project
cd my_project
composer require templating twig frameworkbundle"><pre class="notranslate">composer create-project symfony/skeleton my_project
<span class="pl-c1">cd</span> my_project
composer require templating twig frameworkbundle</pre></div>
<p dir="auto">Add to <code class="notranslate">config/services.yaml</code></p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    App\Controller\MyController:
        arguments:
            $template_finder: &quot;@templating.finder&quot;
        public: true"><pre class="notranslate">    <span class="pl-ent">App\Controller\MyController</span>:
        <span class="pl-ent">arguments</span>:
            <span class="pl-ent">$template_finder</span>: <span class="pl-s"><span class="pl-pds">"</span>@templating.finder<span class="pl-pds">"</span></span>
        <span class="pl-ent">public</span>: <span class="pl-c1">true</span></pre></div>
<p dir="auto">Add to <code class="notranslate">src/Controller/MyController.php</code></p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;?php
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinder;
use Symfony\Component\HttpFoundation\Response;

class MyController
{
    private $twig;
    private $template_finder;

    public function __construct(\Twig_Environment $environment, TemplateFinder $template_finder)
    {
        $this-&gt;twig = $environment;
        $this-&gt;template_finder = $template_finder;
    }

    public function listTemplates()
    {
        return new Response(
            $this-&gt;twig-&gt;render('templates.html.twig', ['templates' =&gt; $this-&gt;template_finder-&gt;findAllTemplates()])
        );
    }
}"><pre class="notranslate"><span class="pl-ent">&lt;?php</span>
<span class="pl-k">namespace</span> <span class="pl-v">App</span>\<span class="pl-v">Controller</span>;

<span class="pl-k">use</span> <span class="pl-v">Symfony</span>\<span class="pl-v">Bundle</span>\<span class="pl-v">FrameworkBundle</span>\<span class="pl-v">CacheWarmer</span>\<span class="pl-v">TemplateFinder</span>;
<span class="pl-k">use</span> <span class="pl-v">Symfony</span>\<span class="pl-v">Component</span>\<span class="pl-v">HttpFoundation</span>\<span class="pl-v">Response</span>;

<span class="pl-k">class</span> <span class="pl-v">MyController</span>
{
    <span class="pl-k">private</span> <span class="pl-c1"><span class="pl-c1">$</span>twig</span>;
    <span class="pl-k">private</span> <span class="pl-c1"><span class="pl-c1">$</span>template_finder</span>;

    <span class="pl-k">public</span> <span class="pl-k">function</span> <span class="pl-en">__construct</span>(<span class="pl-smi"><span class="pl-smi">\<span class="pl-v">Twig_Environment</span></span></span> <span class="pl-s1"><span class="pl-c1">$</span>environment</span>, <span class="pl-smi"><span class="pl-smi">TemplateFinder</span></span> <span class="pl-s1"><span class="pl-c1">$</span>template_finder</span>)
    {
        <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">twig</span> = <span class="pl-s1"><span class="pl-c1">$</span>environment</span>;
        <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">template_finder</span> = <span class="pl-s1"><span class="pl-c1">$</span>template_finder</span>;
    }

    <span class="pl-k">public</span> <span class="pl-k">function</span> <span class="pl-en">listTemplates</span>()
    {
        <span class="pl-k">return</span> <span class="pl-k">new</span> <span class="pl-v">Response</span>(
            <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">twig</span>-&gt;<span class="pl-en">render</span>(<span class="pl-s">'templates.html.twig'</span>, [<span class="pl-s">'templates'</span> =&gt; <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">template_finder</span>-&gt;<span class="pl-en">findAllTemplates</span>()])
        );
    }
}</pre></div>
<p dir="auto">Add to <code class="notranslate">config/routes.yaml</code></p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="index:
    path: /
    controller: App\Controller\MyController::listTemplates"><pre class="notranslate"><span class="pl-ent">index</span>:
    <span class="pl-ent">path</span>: <span class="pl-s">/</span>
    <span class="pl-ent">controller</span>: <span class="pl-s">App\Controller\MyController::listTemplates</span></pre></div>
<p dir="auto">Finally, add to <code class="notranslate">templates/templates.html.twig</code></p>
<div class="highlight highlight-text-html-twig notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{% extends &quot;base.html.twig&quot; %}
{% block body %}
    {% for template in templates %}
        {{ template }}&lt;br /&gt;
    {% endfor %}
{% endblock %}"><pre class="notranslate">{% <span class="pl-k">extends</span> <span class="pl-s"><span class="pl-pds">"</span>base.html.twig<span class="pl-pds">"</span></span> %}
{% <span class="pl-k">block</span> <span class="pl-smi">body</span> %}
    {% <span class="pl-k">for</span> <span class="pl-smi">template</span> <span class="pl-k">in</span> <span class="pl-smi">templates</span> %}
        {{ <span class="pl-smi">template</span> }}&lt;<span class="pl-ent">br</span> /&gt;
    {% <span class="pl-k">endfor</span> %}
{% <span class="pl-k">endblock</span> %}</pre></div>
<p dir="auto">Expected: <code class="notranslate">base.html.twig</code> and <code class="notranslate">templates.html.twig</code> part of the output<br>
Result: Only files inside the <code class="notranslate">FrameworkBundle</code> and <code class="notranslate">TwigBundle</code> found.</p>