Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

ECS command fails due to deprecation in symfony console #4449

Closed
stefangr opened this issue Oct 24, 2022 · 14 comments
Closed

ECS command fails due to deprecation in symfony console #4449

stefangr opened this issue Oct 24, 2022 · 14 comments

Comments

@stefangr
Copy link
Contributor

stefangr commented Oct 24, 2022

Since ecs version 11.1.11, all usages of the ecs command fail with the following error:

[24-Oct-2022 08:16:22 Europe/Berlin] PHP Fatal error:  Uncaught Error: Call to undefined function ECSPrefix202210\trigger_deprecation() in vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/Command.php:116
Stack trace:
#0 vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/Command.php(140): ECSPrefix202210\Symfony\Component\Console\Command\Command::getDefaultName()
#1 vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/CompleteCommand.php(49): ECSPrefix202210\Symfony\Component\Console\Command\Command->__construct()
#2 vendor/symplify/easy-coding-standard/vendor/symfony/console/Application.php(948): ECSPrefix202210\Symfony\Component\Console\Command\CompleteCommand->__construct()
#3 vendor/symplify/easy-coding-standard/ven in vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/Command.php on line 116

Within the symfony console command class in the new ecs version the trigger_deprecation function is called.
This was not the case in version 11.1.10.

@TomasVotruba
Copy link
Member

HI,
I've just run fresh ECS install and run check on PHP 7.2, 7.4 and 8.0 and it works.

What are the reproducer steps?

Try removing /vendor and install fresh version. It might be autoload issue.

@PhilETaylor
Copy link

Just to say they are not alone, I too have had this for a while in several projects. (running pre-released versions, on PHP 8.2 cli used at all times)

updated today which gave 11.1.11 and now have this error too.

However on a quick attempt to give you a reproducer, I failed - and it worked.

@TomasVotruba
Copy link
Member

@PhilETaylor How does it behave after removing /vendor in your project?

@PhilETaylor
Copy link

I removed vendor and then ran a new composer update and I get the same.

Just tested on other projects after a composer update and I can replicate on each project (not isolated the problem yet though)

@PhilETaylor
Copy link

100% unrelated but one to watch for future too symfony/symfony#47904

@webard
Copy link

webard commented Oct 24, 2022

In my project bug exists after last update, i have fresh vendor install:

> vendor/bin/ecs check --fix
PHP Fatal error:  Uncaught Error: Call to undefined function ECSPrefix202210\trigger_deprecation() in /var/www/html/vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/Command.php:116
Stack trace:
#0 /var/www/html/vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/Command.php(140): ECSPrefix202210\Symfony\Component\Console\Command\Command::getDefaultName()
#1 /var/www/html/vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/CompleteCommand.php(49): ECSPrefix202210\Symfony\Component\Console\Command\Command->__construct()
#2 /var/www/html/vendor/symplify/easy-coding-standard/vendor/symfony/console/Application.php(948): ECSPrefix202210\Symfony\Component\Console\Command\CompleteCommand->__construct()
#3 /var/www/html/vendor/symplify/easy-coding-standard/vendor/symfony/console/Application.php(1093): ECSPrefix202210\Symfony\Component\Console\Application->getDefaultCommands()
#4 /var/www/html/vendor/symplify/easy-coding-standard/vendor/symfony/console/Application.php(481): ECSPrefix202210\Symfony\Component\Console\Application->init()
#5 /var/www/html/vendor/symplify/easy-coding-standard/vendor/symfony/console/Application.php(468): ECSPrefix202210\Symfony\Component\Console\Application->add()
#6 /var/www/html/vendor/symplify/easy-coding-standard/src/Console/EasyCodingStandardConsoleApplication.php(25): ECSPrefix202210\Symfony\Component\Console\Application->addCommands()
#7 [internal function]: Symplify\EasyCodingStandard\Console\EasyCodingStandardConsoleApplication->__construct()
#8 /var/www/html/vendor/symplify/easy-coding-standard/vendor/symfony/dependency-injection/ContainerBuilder.php(894): ReflectionClass->newInstanceArgs()
#9 /var/www/html/vendor/symplify/easy-coding-standard/vendor/symfony/dependency-injection/ContainerBuilder.php(490): ECSPrefix202210\Symfony\Component\DependencyInjection\ContainerBuilder->createService()
#10 /var/www/html/vendor/symplify/easy-coding-standard/vendor/symfony/dependency-injection/ContainerBuilder.php(441): ECSPrefix202210\Symfony\Component\DependencyInjection\ContainerBuilder->doGet()
#11 /var/www/html/vendor/symplify/easy-coding-standard/bin/ecs.php(128): ECSPrefix202210\Symfony\Component\DependencyInjection\ContainerBuilder->get()
#12 /var/www/html/vendor/symplify/easy-coding-standard/bin/ecs(5): require('...')
#13 /var/www/html/vendor/bin/ecs(120): include('...')
#14 {main}
  thrown in /var/www/html/vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/Command.php on line 116
Script vendor/bin/ecs check --fix handling the fix-style event returned with error code 255

Downgrading symplify/easy-coding-standard to 11.1.10 resolve issue, so last update must be related.

@PhilETaylor
Copy link

PhilETaylor commented Oct 24, 2022

@TomasVotruba reproducer below...

composer require symplify/easy-coding-standard
composer require symfony/console
vendor/bin/ecs

Gives this output:

composer require symplify/easy-coding-standard

Using version ^11.1 for symplify/easy-coding-standard
./composer.json has been created
Running composer update symplify/easy-coding-standard
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking symplify/easy-coding-standard (11.1.11)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing symplify/easy-coding-standard (11.1.11): Extracting archive
Generating autoload files
1 package you are using is looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found






~/Sites/reproducer2 vendor/bin/ecs


 [ERROR] We could not find any sniffs/fixers rules to run


You have few options to add them:

Add single rule to "ecs.php"
============================

  $ecsConfig->rule(...);


Add set of rules to "ecs.php"
=============================

  $ecsConfig->sets([...]);


Missing "ecs.php" in your project? Let ECS create it for you
============================================================

  vendor/bin/ecs init




~/Sites/reproducer2 composer require symfony/console


Using version ^6.1 for symfony/console
./composer.json has been updated
Running composer update symfony/console
Loading composer repositories with package information
Updating dependencies
Lock file operations: 9 installs, 0 updates, 0 removals
  - Locking psr/container (2.0.2)
  - Locking symfony/console (v6.1.6)
  - Locking symfony/deprecation-contracts (v3.1.1)
  - Locking symfony/polyfill-ctype (v1.26.0)
  - Locking symfony/polyfill-intl-grapheme (v1.26.0)
  - Locking symfony/polyfill-intl-normalizer (v1.26.0)
  - Locking symfony/polyfill-mbstring (v1.26.0)
  - Locking symfony/service-contracts (v3.1.1)
  - Locking symfony/string (v6.1.6)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 9 installs, 0 updates, 0 removals
  - Installing symfony/polyfill-mbstring (v1.26.0): Extracting archive
  - Installing symfony/polyfill-intl-normalizer (v1.26.0): Extracting archive
  - Installing symfony/polyfill-intl-grapheme (v1.26.0): Extracting archive
  - Installing symfony/polyfill-ctype (v1.26.0): Extracting archive
  - Installing symfony/string (v6.1.6): Extracting archive
  - Installing psr/container (2.0.2): Extracting archive
  - Installing symfony/service-contracts (v3.1.1): Extracting archive
  - Installing symfony/deprecation-contracts (v3.1.1): Extracting archive
  - Installing symfony/console (v6.1.6): Extracting archive
5 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating autoload files
9 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found




~/Sites/reproducer2 vendor/bin/ecs




PHP Fatal error:  Uncaught Error: Call to undefined function ECSPrefix202210\trigger_deprecation() in /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/Command.php:116
Stack trace:
#0 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/Command.php(140): ECSPrefix202210\Symfony\Component\Console\Command\Command::getDefaultName()
#1 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/CompleteCommand.php(49): ECSPrefix202210\Symfony\Component\Console\Command\Command->__construct()
#2 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/console/Application.php(948): ECSPrefix202210\Symfony\Component\Console\Command\CompleteCommand->__construct()
#3 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/console/Application.php(1093): ECSPrefix202210\Symfony\Component\Console\Application->getDefaultCommands()
#4 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/console/Application.php(481): ECSPrefix202210\Symfony\Component\Console\Application->init()
#5 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/console/Application.php(468): ECSPrefix202210\Symfony\Component\Console\Application->add(Object(Symplify\EasyCodingStandard\Console\Command\CheckCommand))
#6 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/src/Console/EasyCodingStandardConsoleApplication.php(25): ECSPrefix202210\Symfony\Component\Console\Application->addCommands(Array)
#7 [internal function]: Symplify\EasyCodingStandard\Console\EasyCodingStandardConsoleApplication->__construct(Array)
#8 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/dependency-injection/ContainerBuilder.php(894): ReflectionClass->newInstanceArgs(Array)
#9 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/dependency-injection/ContainerBuilder.php(490): ECSPrefix202210\Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object(ECSPrefix202210\Symfony\Component\DependencyInjection\Definition), Array, true, 'Symplify\\EasyCo...')
#10 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/dependency-injection/ContainerBuilder.php(441): ECSPrefix202210\Symfony\Component\DependencyInjection\ContainerBuilder->doGet('Symplify\\EasyCo...', 1)
#11 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/bin/ecs.php(128): ECSPrefix202210\Symfony\Component\DependencyInjection\ContainerBuilder->get('Symplify\\EasyCo...')
#12 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/bin/ecs(5): require('/Users/phil/Sit...')
#13 /Users/phil/Sites/reproducer2/vendor/bin/ecs(120): include('/Users/phil/Sit...')
#14 {main}
  thrown in /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/Command.php on line 116

Fatal error: Uncaught Error: Call to undefined function ECSPrefix202210\trigger_deprecation() in /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/Command.php:116
Stack trace:
#0 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/Command.php(140): ECSPrefix202210\Symfony\Component\Console\Command\Command::getDefaultName()
#1 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/CompleteCommand.php(49): ECSPrefix202210\Symfony\Component\Console\Command\Command->__construct()
#2 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/console/Application.php(948): ECSPrefix202210\Symfony\Component\Console\Command\CompleteCommand->__construct()
#3 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/console/Application.php(1093): ECSPrefix202210\Symfony\Component\Console\Application->getDefaultCommands()
#4 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/console/Application.php(481): ECSPrefix202210\Symfony\Component\Console\Application->init()
#5 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/console/Application.php(468): ECSPrefix202210\Symfony\Component\Console\Application->add(Object(Symplify\EasyCodingStandard\Console\Command\CheckCommand))
#6 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/src/Console/EasyCodingStandardConsoleApplication.php(25): ECSPrefix202210\Symfony\Component\Console\Application->addCommands(Array)
#7 [internal function]: Symplify\EasyCodingStandard\Console\EasyCodingStandardConsoleApplication->__construct(Array)
#8 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/dependency-injection/ContainerBuilder.php(894): ReflectionClass->newInstanceArgs(Array)
#9 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/dependency-injection/ContainerBuilder.php(490): ECSPrefix202210\Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object(ECSPrefix202210\Symfony\Component\DependencyInjection\Definition), Array, true, 'Symplify\\EasyCo...')
#10 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/dependency-injection/ContainerBuilder.php(441): ECSPrefix202210\Symfony\Component\DependencyInjection\ContainerBuilder->doGet('Symplify\\EasyCo...', 1)
#11 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/bin/ecs.php(128): ECSPrefix202210\Symfony\Component\DependencyInjection\ContainerBuilder->get('Symplify\\EasyCo...')
#12 /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/bin/ecs(5): require('/Users/phil/Sit...')
#13 /Users/phil/Sites/reproducer2/vendor/bin/ecs(120): include('/Users/phil/Sit...')
#14 {main}
  thrown in /Users/phil/Sites/reproducer2/vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/Command.php on line 116

@PhilETaylor
Copy link

actually can also be reproduced with just

composer require symplify/easy-coding-standard
composer require symfony/deprecation-contracts
vendor/bin/ecs

@des1roer
Copy link

easy-coding-standard/easy-coding-standard#19

@rez1dent3
Copy link
Contributor

rez1dent3 commented Oct 24, 2022

+1. Build: https://github.com/bavix/laravel-wallet/actions/runs/3313988563/jobs/5472688593

PHP Fatal error:  Uncaught Error: Call to undefined function ECSPrefix202210\trigger_deprecation() in /home/runner/work/laravel-wallet/laravel-wallet/vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/Command.php:116
Stack trace:
#0 /home/runner/work/laravel-wallet/laravel-wallet/vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/Command.php(140): ECSPrefix2022[10](https://github.com/bavix/laravel-wallet/actions/runs/3313988563/jobs/5472688593#step:7:11)\Symfony\Component\Console\Command\Command::getDefaultName()
#1 /home/runner/work/laravel-wallet/laravel-wallet/vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/CompleteCommand.php(49): ECSPrefix202210\Symfony\Component\Console\Command\Command->__construct()
#2 /home/runner/work/laravel-wallet/laravel-wallet/vendor/symplify/easy-coding-standard/vendor/symfony/console/Application.php(948): ECSPrefix202210\Symfony\Component\Console\Command\CompleteCommand->__construct()
#3 /home/runner/work/laravel-wallet/laravel-wallet/vendor/symplify/easy-coding-standard/vendor/symfony/console/Application.php(1093): ECSPrefix202210\Symfony\Component\Console\Application->getDefaultCommands()
#4 /home/runner/work/laravel-wallet/laravel-wallet/vendor/symplify/easy-coding-standard/vendor/symfony/console/Application.php(481): ECSPrefix202210\Symfony\Component\Console\Application->init()
#5 /home/runner/work/laravel-wallet/laravel-wallet/vendor/symplify/easy-coding-standard/vendor/symfony/console/Application.php(468): ECSPrefix202210\Symfony\Component\Console\Application->add()
#6 /home/runner/work/laravel-wallet/laravel-wallet/vendor/symplify/easy-coding-standard/src/Console/EasyCodingStandardConsoleApplication.php(25): ECSPrefix202210\Symfony\Component\Console\Application->addCommands()
#7 [internal function]: Symplify\EasyCodingStandard\Console\EasyCodingStandardConsoleApplication->__construct()
#8 /home/runner/work/laravel-wallet/laravel-wallet/vendor/symplify/easy-coding-standard/vendor/symfony/dependency-injection/ContainerBuilder.php(894): ReflectionClass->newInstanceArgs()
#9 /home/runner/work/laravel-wallet/laravel-wallet/vendor/symplify/easy-coding-standard/vendor/symfony/dependency-injection/ContainerBuilder.php(490): ECSPrefix202210\Symfony\Component\DependencyInjection\ContainerBuilder->createService()
#10 /home/runner/work/laravel-wallet/laravel-wallet/vendor/symplify/easy-coding-standard/vendor/symfony/dependency-injection/ContainerBuilder.php(441): ECSPrefix202210\Symfony\Component\DependencyInjection\ContainerBuilder->doGet()
#[11](https://github.com/bavix/laravel-wallet/actions/runs/3313988563/jobs/5472688593#step:7:12) /home/runner/work/laravel-wallet/laravel-wallet/vendor/symplify/easy-coding-standard/bin/ecs.php([12](https://github.com/bavix/laravel-wallet/actions/runs/3313988563/jobs/5472688593#step:7:13)8): ECSPrefix202210\Symfony\Component\DependencyInjection\ContainerBuilder->get()
#12 /home/runner/work/laravel-wallet/laravel-wallet/vendor/symplify/easy-coding-standard/bin/ecs(5): require('...')
#[13](https://github.com/bavix/laravel-wallet/actions/runs/3313988563/jobs/5472688593#step:7:14) /home/runner/work/laravel-wallet/laravel-wallet/vendor/bin/ecs(120): include('...')
#[14](https://github.com/bavix/laravel-wallet/actions/runs/3313988563/jobs/5472688593#step:7:15) {main}
  thrown in /home/runner/work/laravel-wallet/laravel-wallet/vendor/symplify/easy-coding-standard/vendor/symfony/console/Command/Command.php on line 1[16](https://github.com/bavix/laravel-wallet/actions/runs/3313988563/jobs/5472688593#step:7:17)
Script @php vendor/bin/ecs check handling the ecs event returned with error code [25](https://github.com/bavix/laravel-wallet/actions/runs/3313988563/jobs/5472688593#step:7:26)5
Error: Process completed with exit code 255.

Might help solve the problem (ECS config): https://github.com/bavix/laravel-wallet/blob/df0eb5326590f68953ea2053def859c1e743a6f5/ecs.php

@stefangr
Copy link
Contributor Author

In the projects where I have this issue I do have the symfony/deprecation-contracts package required (as secondary dependency).

I dug deeper into finding out why this is happening.

There are two composer autoload instances in use:

  • the generated composer autoload files for my project's code and dependencies
  • the generated composer autoload files for the easy conding standard package and it's dependencies

They both define an autoload_static.php file that contain the files that need to be required to autoload functions.

The cause of the issue is that both autoload_static.php files contain this line in the $files array:

'6e3fae29631ef280660b3cdad06f25a8' => __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php',

The key is an md5 hash of the name of the composer package and the path to the file to require (defined in the composer.json of the package).

In the autoload_real.php a function is defined that is used to require these files.
But this function uses a global array to make sure that the same file is not required more that once.
The mentioned key is used in that function.

So the issue is that my project's autoload files are required and the autoload files from the ECS dependencies that have the same key in that $files array are not required.

@TomasVotruba
Copy link
Member

@stefangr Thank you, this is super helpful 👍
I was able to add a reproducer CI job: https://github.com/symplify/easy-coding-standard/actions/runs/3314841283/jobs/5474649097

@theofidry
Copy link
Contributor

@TomasVotruba FYI this not exactly a new problem, just one exacerbated by the increasing usage of Symfony's trigger_deprecation which is a problematic case.

If you want to follow a long term solution I suggest you to follow humbug/php-scoper#682

@TomasVotruba
Copy link
Member

@theofidry Thanks for reaching out. I saw your issue in Symfony for making non-global functions, and I second that 👍

Yeah, I've had similar issue with other global functions. It's a bad practise and should be avoided in general.
Thanks for sharing the link to the possible solution, I'd be happy to us this option 👍

@deprecated-packages deprecated-packages locked as resolved and limited conversation to collaborators Feb 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

7 participants