简体   繁体   中英

PHP 7.2 throws run "composer require symfony/dotenv", 7.1 does not

A Symfony 4.2 application built (& working) in PHP 7.1, when switched to 7.2 throws

Fatal error: Uncaught RuntimeException: Please run "composer require symfony/dotenv" to load the ".env" files configuring the application...

Further, composer update yields Nothing to install or update and then

Script cache:clear returned with error code 255 !! !! Fatal error: Uncaught RuntimeException: You need to add "symfony/framework-bundle" as a Composer dependency. in G:\\Documents\\workspace\\mana\\bin\\console:14

After updating composer.json to require PHP 7.2, it now includes:

"require": {
    "php": "^7.2",
    "ext-ctype": "*",
    "ext-iconv": "*",
    "beberlei/doctrineextensions": "^1.1",
    "easycorp/easyadmin-bundle": "^2.0",
    "knplabs/knp-snappy-bundle": "^1.6",
    "ob/highcharts-bundle": "^1.6",
    "sensio/framework-extra-bundle": "^5.1",
    "symfony/asset": "4.2.*",
    "symfony/console": "4.2.*",
    "symfony/dotenv": "4.2.*",
    "symfony/expression-language": "4.2.*",
    "symfony/flex": "^1.1",
    "symfony/form": "4.2.*",
    "symfony/framework-bundle": "4.2.*",
    "symfony/monolog-bundle": "^3.1",
    "symfony/orm-pack": "*",
    "symfony/process": "4.2.*",
    "symfony/security-bundle": "4.2.*",
    "symfony/serializer-pack": "*",
    "symfony/swiftmailer-bundle": "^3.1",
    "symfony/templating": "4.2.*",
    "symfony/test-pack": "^1.0",
    "symfony/translation": "4.2.*",
    "symfony/twig-bundle": "4.2.*",
    "symfony/validator": "4.2.*",
    "symfony/web-link": "4.2.*",
    "symfony/webpack-encore-bundle": "^1.0",
    "symfony/yaml": "4.2.*"
},

Edit: If, as suggested in the error message, composer update is run, the following occurs. As can be seen in composer.json above, this is nonsensical.

Fatal error: Uncaught RuntimeException: You need to add "symfony/framework-bundle" as a Composer dependency. in G:\\Documents\\workspace\\mana\\bin\\console:14

Edit #2: This does not appear to be a Symfony or a PHP issue. I'm working in Windows and have a Hyper-V Ububtu 18 server running a clone of the app in Apache/2.4.29, PHP Version 7.2.19 without a problem. Makes it a whole lot harder to sort out. Place this Q on hold?

Edit #3: Restored a two month old Windows image and got the same effect. Returned to current image and learned that the errors described above start somewhere between PHP 7.10 & 7.16 on this box. Upgrading Symfony to 4.3 does not help. ARRRGGGHHH!

Final edit: Sorting this out is beyond my skill set. I'll end with the output of PHP 7.2.20. There is no dev.log created. Netbeans 11 does not seem to recognize xdebug. Here:

(1/1) FatalErrorException

Error: During class fetch: Uncaught ReflectionException: Class PHPUnit\\Framework\\TestCase not found in G:\\Documents\\workspace\\mana\\vendor\\symfony\\framework-bundle\\Test\\KernelTestCase.php:24 Stack trace:

0 G:\\Documents\\workspace\\mana\\vendor\\symfony\\debug\\DebugClassLoader.php(159):

require('G:\\Documents\\wo...')

1 [internal function]: Symfony\\Component\\Debug\\DebugClassLoader->loadClass('Symfony\\Bundle\\...')

2 G:\\Documents\\workspace\\mana\\vendor\\symfony\\framework-bundle\\Test\\WebTestCase.php(22):

spl_autoload_call('Symfony\\Bundle\\...')

3 G:\\Documents\\workspace\\mana\\vendor\\symfony\\debug\\DebugClassLoader.php(159):

require('G:\\Documents\\wo...')

4 [internal function]: Symfony\\Component\\Debug\\DebugClassLoader->loadClass('Symfony\\Bundle\\...')

5 G:\\Documents\\workspace\\mana\\vendor\\liip\\functional-test-bundle\\src\\Test\\WebTestCase.php(41):

spl_autoload_call('Symfony\\Bundle\\...')

6 G:\\Documents\\workspace\\mana\\vendor\\symfony\\debug\\DebugClassLoader.php(159):

require('G:\\Documents\\wo...')

7 [internal function]: Sy in KernelTestCase.php line 24

I also encountered this issue, but in my case the issue is that composer had updated to 2.0.11 and that's what generated the error regarding that Please run "composer require symfony/dotenv" to load the ".env" files configuring the application. I went back to composer 2.0.8 and all was well again. I believe 2.0.9 also works.

I had this problem for almost three hours now. It turns out that I had to downgrade my flex version to 1.6 because higher versions of flex require dotenv version of at least 4.4.

I found that solution approach here: https://github.com/symfony/flex/pull/570

使用最简单的解决方案摆脱困境 - 一直升级到 PHP 7.3.7。

This is fairly old, but I ran into this problem extensively recently and since I am not at all familiar with PHP it was driving me insane. Just wanted to post this in case it could help anyone else. It seems that the load path is simply messed up at times with regards to symfony/dotenv . By running the following line, I was able to "live require" dotenv, even while the normal PHP loading mechanism would not quite do it:

sed '14irequire("/var/www/html/vendor/symfony/dotenv/Dotenv.php");' -i /var/www/html/vendor/symfony/flex/src/Command/DumpEnvCommand.php;

The leading /var/www/html would get replaced with whatever comes before your vendor/ directory. All that it does is insert a require statement to the file that does not seem to be correctly required by PHP. After running this, I could run composer dump-env prod with no errors.

I wouldn't really call it the most elegant solution, but it did get the job done for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM