Skip to content

[Dotenv] Emebed commands inside .env files makes the application crash #38201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tristanbes opened this issue Sep 15, 2020 · 3 comments
Closed

Comments

@tristanbes
Copy link
Contributor

tristanbes commented Sep 15, 2020

Symfony version(s) affected: 4.4.13

Description
When adding an embed command inside the .env and run the composer dump-env prod, the application crashes:

PHP Fatal error:  Uncaught Error: Call to undefined method Symfony\Component\Process\Process::inheritEnvironmentVariables() in /Users/tbessoussa/workspace/dotenv-reproducer/vendor/symfony/dotenv/Dotenv.php:406
Stack trace:
#0 [internal function]: Symfony\Component\Dotenv\Dotenv->Symfony\Component\Dotenv\{closure}(Array)
#1 /Users/tbessoussa/workspace/dotenv-reproducer/vendor/symfony/dotenv/Dotenv.php(389): preg_replace_callback('/\n            (...', Object(Closure), '$(git rev-parse...')
#2 /Users/tbessoussa/workspace/dotenv-reproducer/vendor/symfony/dotenv/Dotenv.php(320): Symfony\Component\Dotenv\Dotenv->resolveCommands('$(git rev-parse...', Array)
#3 /Users/tbessoussa/workspace/dotenv-reproducer/vendor/symfony/dotenv/Dotenv.php(200): Symfony\Component\Dotenv\Dotenv->lexValue()
#4 /Users/tbessoussa/workspace/dotenv-reproducer/vendor/symfony/dotenv/Dotenv.php(513): Symfony\Component\Dotenv\Dotenv->parse('# In all enviro...', './.env')
#5 /Users/tbessoussa/workspace/dotenv-reproducer/vendor/symfony/dotenv/Dotenv.php(65): Symf in /Users/tbessoussa/workspace/dotenv-reproducer/vendor/symfony/dotenv/Dotenv.php on line 406

Fatal error: Uncaught Error: Call to undefined method Symfony\Component\Process\Process::inheritEnvironmentVariables() in /Users/tbessoussa/workspace/dotenv-reproducer/vendor/symfony/dotenv/Dotenv.php:406
Stack trace:
#0 [internal function]: Symfony\Component\Dotenv\Dotenv->Symfony\Component\Dotenv\{closure}(Array)
#1 /Users/tbessoussa/workspace/dotenv-reproducer/vendor/symfony/dotenv/Dotenv.php(389): preg_replace_callback('/\n            (...', Object(Closure), '$(git rev-parse...')
#2 /Users/tbessoussa/workspace/dotenv-reproducer/vendor/symfony/dotenv/Dotenv.php(320): Symfony\Component\Dotenv\Dotenv->resolveCommands('$(git rev-parse...', Array)
#3 /Users/tbessoussa/workspace/dotenv-reproducer/vendor/symfony/dotenv/Dotenv.php(200): Symfony\Component\Dotenv\Dotenv->lexValue()
#4 /Users/tbessoussa/workspace/dotenv-reproducer/vendor/symfony/dotenv/Dotenv.php(513): Symfony\Component\Dotenv\Dotenv->parse('# In all enviro...', './.env')
#5 /Users/tbessoussa/workspace/dotenv-reproducer/vendor/symfony/dotenv/Dotenv.php(65): Symf in /Users/tbessoussa/workspace/dotenv-reproducer/vendor/symfony/dotenv/Dotenv.php on line 406

How to reproduce
You can use the reproducer here: tristanbes/process-reproducer#1

But you can test by just simply adding SOURCE_VERSION=$(git rev-parse HEAD) inside your .env and running composer dump-env prod you end up with a fatal error.

Additional context

Composer version 1.10.10 2020-08-03 11:35:19
Tested PHP version: 7.4.9, 7.4.10
Tested OS: MacOS with zsh / Debian 10 with zsh 

Also tested and reproduced with Platform.sh

As stated in the documentation, it should be possible doing so
and it was working in previous version of Symfony

The_Dotenv_Component__Symfony_4_3_Docs_

@tristanbes tristanbes added the Bug label Sep 15, 2020
@tristanbes tristanbes changed the title Emebed commands inside .env files makes the application crash [DotEnv] Emebed commands inside .env files makes the application crash Sep 15, 2020
@tristanbes tristanbes changed the title [DotEnv] Emebed commands inside .env files makes the application crash [Dotenv] Emebed commands inside .env files makes the application crash Sep 15, 2020
@chalasr chalasr added the Dotenv label Sep 15, 2020
@hallboav
Copy link
Contributor

Is it a symfony/dotenv issue? No.

mkdir /tmp/issue-38201 \
&& pushd /tmp/issue-38201 \
&& composer req symfony/dotenv:4.4.13 symfony/process:4.4.13 \
&& echo "SOME_ENV=\$(date +%s)" > .env \
&& php << 'DOTENV_TEST'
<?php
require 'vendor/autoload.php'; 
$dotenv = new \Symfony\Component\Dotenv\Dotenv();
$dotenv->loadEnv(__DIR__ . '/.env');
echo PHP_EOL, "\033[5;32m", $_ENV['SOME_ENV'], "\033[0m", PHP_EOL, PHP_EOL;
DOTENV_TEST
popd
rm -r /tmp/issue-38201

@hallboav
Copy link
Contributor

The problem happens when using symfony/flex's DumpEnvCommand command.
This exception isn't being thrown even if no symfony/process is installed at all.
Why?

@Chi-teck
Copy link
Contributor

Chi-teck commented Nov 14, 2020

Faced the same issue. As this command is running through Composer it shares its dependencies. So that symfony/process is always available because Composer depends on it. Apparently the inheritEnvironmentVariables method did not exist in symfony/process v2 which is used in composer.phar.

@fabpot fabpot closed this as completed Nov 17, 2020
fabpot added a commit that referenced this issue Nov 17, 2020
…s (Chi-teck)

This PR was merged into the 4.4 branch.

Discussion
----------

[Dotenv] Check if method inheritEnvironmentVariables exists

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #38201
| License       | MIT
| Doc PR        | -

Commits
-------

bd72a56 Check if method inheritEnvironmentVariables exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants