<p dir="auto">Hello,</p>
<p dir="auto">When i run the code below, on the second search, the results are duplicated.</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$finder = new Finder();
$first_results = $finder-&gt;in('/my/path')-&gt;files()-&gt;name('/my_pattern/');

 // [...] some code

$second_results = $finder-&gt;in('/my/path')-&gt;files()-&gt;name('/another_pattern/');"><pre class="notranslate"><span class="pl-s1"><span class="pl-c1">$</span>finder</span> = <span class="pl-k">new</span> <span class="pl-v">Finder</span>();
<span class="pl-s1"><span class="pl-c1">$</span>first_results</span> = <span class="pl-s1"><span class="pl-c1">$</span>finder</span>-&gt;<span class="pl-en">in</span>(<span class="pl-s">'/my/path'</span>)-&gt;<span class="pl-en">files</span>()-&gt;<span class="pl-en">name</span>(<span class="pl-s">'/my_pattern/'</span>);

 <span class="pl-c">// [...] some code</span>

<span class="pl-s1"><span class="pl-c1">$</span>second_results</span> = <span class="pl-s1"><span class="pl-c1">$</span>finder</span>-&gt;<span class="pl-en">in</span>(<span class="pl-s">'/my/path'</span>)-&gt;<span class="pl-en">files</span>()-&gt;<span class="pl-en">name</span>(<span class="pl-s">'/another_pattern/'</span>);</pre></div>
<p dir="auto">But if i run that code, it works as intended :</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$finder = new Finder();
$first_results = $finder-&gt;in('/my/path')-&gt;files()-&gt;name('/my_pattern/');

 // [...] some code

$finder = new Finder();
$second_results = $finder-&gt;in('/my/path')-&gt;files()-&gt;name('/another_pattern/');"><pre class="notranslate"><span class="pl-s1"><span class="pl-c1">$</span>finder</span> = <span class="pl-k">new</span> <span class="pl-v">Finder</span>();
<span class="pl-s1"><span class="pl-c1">$</span>first_results</span> = <span class="pl-s1"><span class="pl-c1">$</span>finder</span>-&gt;<span class="pl-en">in</span>(<span class="pl-s">'/my/path'</span>)-&gt;<span class="pl-en">files</span>()-&gt;<span class="pl-en">name</span>(<span class="pl-s">'/my_pattern/'</span>);

 <span class="pl-c">// [...] some code</span>

<span class="pl-s1"><span class="pl-c1">$</span>finder</span> = <span class="pl-k">new</span> <span class="pl-v">Finder</span>();
<span class="pl-s1"><span class="pl-c1">$</span>second_results</span> = <span class="pl-s1"><span class="pl-c1">$</span>finder</span>-&gt;<span class="pl-en">in</span>(<span class="pl-s">'/my/path'</span>)-&gt;<span class="pl-en">files</span>()-&gt;<span class="pl-en">name</span>(<span class="pl-s">'/another_pattern/'</span>);</pre></div>
<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>yes</td>
</tr>
<tr>
<td>RFC?</td>
<td>no</td>
</tr>
<tr>
<td>Symfony version</td>
<td>&gt;=3.4.0</td>
</tr>
</tbody>
</table>
<p dir="auto">I noticed that, when using the dependency injection component without the fullstack framework that the <code class="notranslate">ContainerBuilder</code> cannot be used a container anymore (it was working from Symfony 2.0 to 3.3).</p>
<p dir="auto">The context is the following: when using it with Drupal, it might happen that Drupal modules are being enabled, when they do, they are enabled one by one, implying a container rebuild each time.</p>
<p dir="auto">Problem is that before 3.4, container was loaded using <code class="notranslate">require_once</code> and class name was always the same which lead the container NOT being reloaded even if changed due to <code class="notranslate">require_once</code> usage, and it was also impossible to manually include the file which would have lead to a duplicated class name hence a fatal error.</p>
<p dir="auto">As a simple bypass, I was using this code as a replacement of Kernel::initializeContainer():</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    protected function initializeContainer()
    {
        $class = $this-&gt;getContainerClass();
        $cache = new ConfigCache($this-&gt;getCacheDir().'/'.$class.'.php', $this-&gt;debug);
        $fresh = true;
        if (!$cache-&gt;isFresh()) {
            $container = $this-&gt;buildContainer();
            $container-&gt;compile();
            $this-&gt;dumpContainer($cache, $container, $class, $this-&gt;getContainerBaseClass());

            $fresh = false;

            $this-&gt;container = $container;
        } else {
            require_once $cache-&gt;getPath();

            $this-&gt;container = new $class();
            $this-&gt;container-&gt;set('kernel', $this);
        }

        if (!$fresh &amp;&amp; $this-&gt;container-&gt;has('cache_warmer')) {
            $this-&gt;container-&gt;get('cache_warmer')-&gt;warmUp($this-&gt;container-&gt;getParameter('kernel.cache_dir'));
        }
    }"><pre class="notranslate">    <span class="pl-k">protected</span> <span class="pl-k">function</span> <span class="pl-en">initializeContainer</span>()
    {
        <span class="pl-s1"><span class="pl-c1">$</span>class</span> = <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">getContainerClass</span>();
        <span class="pl-s1"><span class="pl-c1">$</span>cache</span> = <span class="pl-k">new</span> <span class="pl-v">ConfigCache</span>(<span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">getCacheDir</span>().<span class="pl-s">'/'</span>.<span class="pl-s1"><span class="pl-c1">$</span>class</span>.<span class="pl-s">'.php'</span>, <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">debug</span>);
        <span class="pl-s1"><span class="pl-c1">$</span>fresh</span> = <span class="pl-c1">true</span>;
        <span class="pl-k">if</span> (!<span class="pl-s1"><span class="pl-c1">$</span>cache</span>-&gt;<span class="pl-en">isFresh</span>()) {
            <span class="pl-s1"><span class="pl-c1">$</span>container</span> = <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">buildContainer</span>();
            <span class="pl-s1"><span class="pl-c1">$</span>container</span>-&gt;<span class="pl-en">compile</span>();
            <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">dumpContainer</span>(<span class="pl-s1"><span class="pl-c1">$</span>cache</span>, <span class="pl-s1"><span class="pl-c1">$</span>container</span>, <span class="pl-s1"><span class="pl-c1">$</span>class</span>, <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">getContainerBaseClass</span>());

            <span class="pl-s1"><span class="pl-c1">$</span>fresh</span> = <span class="pl-c1">false</span>;

            <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">container</span> = <span class="pl-s1"><span class="pl-c1">$</span>container</span>;
        } <span class="pl-k">else</span> {
            <span class="pl-k">require_once</span> <span class="pl-s1"><span class="pl-c1">$</span>cache</span>-&gt;<span class="pl-en">getPath</span>();

            <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">container</span> = <span class="pl-k">new</span> <span class="pl-s1"><span class="pl-c1">$</span>class</span>();
            <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">container</span>-&gt;<span class="pl-en">set</span>(<span class="pl-s">'kernel'</span>, <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>);
        }

        <span class="pl-k">if</span> (!<span class="pl-s1"><span class="pl-c1">$</span>fresh</span> &amp;&amp; <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">container</span>-&gt;<span class="pl-en">has</span>(<span class="pl-s">'cache_warmer'</span>)) {
            <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">container</span>-&gt;<span class="pl-en">get</span>(<span class="pl-s">'cache_warmer'</span>)-&gt;<span class="pl-en">warmUp</span>(<span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">container</span>-&gt;<span class="pl-en">getParameter</span>(<span class="pl-s">'kernel.cache_dir'</span>));
        }
    }</pre></div>
<p dir="auto">The only notable change in this code is that I don't <code class="notranslate">require_once</code> the container when it is being rebuilt, but use directly the <code class="notranslate">ContainerBuilder</code> instance instead, which was until now gracefully working.</p>
<p dir="auto">Now, if we try that since 3.4, it will fail with a fatal error due to the lack of the <code class="notranslate">container.build_id</code> parameter, and there's a few usages of it with the framework bundle enabled (it is being used as default values for cache adapters version parameter for example).</p>
<p dir="auto">I did bypass this problem with a simple version compare and a fallback on the original Symfony kernel own <code class="notranslate">initializeContainer()</code> method now that the container class name do change thanks to its hashed name, but it is a breaking change:</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    protected function initializeContainer()
    {
        // From Symfony 3.4 only a require and not require_once is being used,
        // we can safely rely upon the parent implementation.
        if (0 &lt;= version_compare(BaseKernel::VERSION, '3.4.0')) {
            return parent::initializeContainer();
        }

        // ..."><pre class="notranslate">    <span class="pl-k">protected</span> <span class="pl-k">function</span> initializeContainer()
    {
        <span class="pl-c">// From Symfony 3.4 only a require and not require_once is being used,</span>
        <span class="pl-c">// we can safely rely upon the parent implementation.</span>
        <span class="pl-k">if</span> (<span class="pl-c1">0</span> &lt;= version_compare(<span class="pl-v">BaseKernel</span>::<span class="pl-c1">VERSION</span>, <span class="pl-s">'3.4.0'</span>)) {
            <span class="pl-k">return</span> <span class="pl-smi">parent</span>::<span class="pl-en">initializeContainer</span>();
        }

        <span class="pl-c">// ...</span></pre></div>
<p dir="auto">Please note that it is very simple to bypass, and it is a very minor breakage since I guess that the <code class="notranslate">ContainerBuilder</code> was not meant to be used a container itself, nevertheless I suspect that other applications that might use the dependency injection manually could one day end up with the same problem - certainly under very, very peculiar conditions (such as the one I experienced).</p>