<p dir="auto">I have this kind of code :</p>
<p dir="auto">classes</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="interface PriceInterface {}
interface VariablePriceInterface extends PriceInterface {}
class ProductPrice implements VariablePriceInterface {}"><pre class="notranslate"><span class="pl-k">interface</span> <span class="pl-v">PriceInterface</span> {}
<span class="pl-k">interface</span> <span class="pl-v">VariablePriceInterface</span> <span class="pl-k">extends</span> <span class="pl-v">PriceInterface</span> {}
<span class="pl-k">class</span> <span class="pl-v">ProductPrice</span> <span class="pl-k">implements</span> <span class="pl-v">VariablePriceInterface</span> {}</pre></div>
<p dir="auto">validation</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="PriceInterface:
    constraints:
        - MyConstraint: ~"><pre class="notranslate"><span class="pl-ent">PriceInterface</span>:
    <span class="pl-ent">constraints</span>:
        - <span class="pl-ent">MyConstraint</span>: <span class="pl-c1">~</span></pre></div>
<p dir="auto">If I validate a <code class="notranslate">ProductPrice</code> object, <code class="notranslate">MyConstraint</code> is checked twice.</p>
<p dir="auto">This is very similar to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="169080062" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/19516" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/19516/hovercard" href="https://github.com/symfony/symfony/issues/19516">#19516</a>.</p>
<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>no</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>&gt;= 3.3</td>
</tr>
</tbody>
</table>
<p dir="auto">First of, I am all in favor of environment variables. I think they are a great way to decouple your app from the server it is ran on.</p>
<p dir="auto">That being said, I'm feeling they are a step backwards in DX compared to the <code class="notranslate">parameters.yml</code> files for different environments when having commands that require them. For instance: if I have a command that does anything with the database (i.e., uses doctrine) I will need to export that correct variables to make it work. <strong>This includes the cache warmup</strong> which warms the doctrine proxies. To illustrate this, here is a quick config:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="parameters:
    database_driver: pdo_mysql
    database_host: %env(DATABASE_HOST)%
    database_port: %env(DATABASE_PORT)%
    database_name: %env(DATABASE_NAME)%
    database_user: %env(DATABASE_USER)%
    database_password: %env(DATABASE_PASSWORD)%
    secret: %env(APP_SECRET)%

framework:
    secret:          &quot;%secret%&quot;
    // [...]

doctrine:
    dbal:
        driver:         &quot;%database_driver%&quot;
        host:           &quot;%database_host%&quot;
        port:           &quot;%database_port%&quot;
        dbname:         &quot;%database_name%&quot;
        user:           &quot;%database_user%&quot;
        password:       &quot;%database_password%&quot;
        charset:        UTF8
// [...]"><pre class="notranslate"><span class="pl-ent">parameters</span>:
    <span class="pl-ent">database_driver</span>: <span class="pl-s">pdo_mysql</span>
    <span class="pl-ent">database_host</span>: <span class="pl-s">%env(DATABASE_HOST)%</span>
    <span class="pl-ent">database_port</span>: <span class="pl-s">%env(DATABASE_PORT)%</span>
    <span class="pl-ent">database_name</span>: <span class="pl-s">%env(DATABASE_NAME)%</span>
    <span class="pl-ent">database_user</span>: <span class="pl-s">%env(DATABASE_USER)%</span>
    <span class="pl-ent">database_password</span>: <span class="pl-s">%env(DATABASE_PASSWORD)%</span>
    <span class="pl-ent">secret</span>: <span class="pl-s">%env(APP_SECRET)%</span>

<span class="pl-ent">framework</span>:
    <span class="pl-ent">secret</span>:          <span class="pl-s"><span class="pl-pds">"</span>%secret%<span class="pl-pds">"</span></span>
    <span class="pl-s">// [...]</span>

<span class="pl-ent">doctrine</span>:
    <span class="pl-ent">dbal</span>:
        <span class="pl-ent">driver</span>:         <span class="pl-s"><span class="pl-pds">"</span>%database_driver%<span class="pl-pds">"</span></span>
        <span class="pl-ent">host</span>:           <span class="pl-s"><span class="pl-pds">"</span>%database_host%<span class="pl-pds">"</span></span>
        <span class="pl-ent">port</span>:           <span class="pl-s"><span class="pl-pds">"</span>%database_port%<span class="pl-pds">"</span></span>
        <span class="pl-ent">dbname</span>:         <span class="pl-s"><span class="pl-pds">"</span>%database_name%<span class="pl-pds">"</span></span>
        <span class="pl-ent">user</span>:           <span class="pl-s"><span class="pl-pds">"</span>%database_user%<span class="pl-pds">"</span></span>
        <span class="pl-ent">password</span>:       <span class="pl-s"><span class="pl-pds">"</span>%database_password%<span class="pl-pds">"</span></span>
        <span class="pl-ent">charset</span>:        <span class="pl-s">UTF8</span>
<span class="pl-s">// [...]</span></pre></div>
<p dir="auto">Which seems to me like the intended prefect example. However, this will throw the following error when running any command:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ bin/console
  [Symfony\Component\DependencyInjection\Exception\EnvNotFoundException]
  Environment variable not found: &quot;DATABASE_HOST&quot;."><pre class="notranslate"><code class="notranslate">$ bin/console
  [Symfony\Component\DependencyInjection\Exception\EnvNotFoundException]
  Environment variable not found: "DATABASE_HOST".
</code></pre></div>
<p dir="auto">Since the environment variables were configured in my Virtual Host settings, they are missing on the command line. So I'm stuck with <a href="https://symfony.com/doc/current/configuration/external_parameters.html#environment-variables" rel="nofollow">creating this <em>massive</em> export block</a> anytime I want to do something on the command line. Worst of all, this includes any deployment script, which needs to preform a cache warmup.</p>
<p dir="auto">So what is the point of this issue?</p>
<p dir="auto">Well I was wondering if we could document in the Symfony docs a good solution to dealing with environment variables for commands. Especially so I do not have to define them twice (vhost &amp; cli exports). Because as it stand now I feel as if the current docs isn't really showing a proper solution.</p>