Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Xdebug 3.0 leads to exception during DI container compile #39195

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
vertexvaar opened this issue Nov 27, 2020 · 7 comments
Closed

Xdebug 3.0 leads to exception during DI container compile #39195

vertexvaar opened this issue Nov 27, 2020 · 7 comments

Comments

@vertexvaar
Copy link
Contributor

Symfony version(s) affected: 5.1.8

Description
Duplicates #30571 in a certain way (but that's closed)
Exception:

PHP Fatal error: Method class@anonymous::__toString() must not throw an exception

When the Exception AutowiringFailedException is constructed with a callback as message and xdebug is installed in version >= 3.0 the condition which resolves the message callback to the actual message string does not work.
Xdebug 3.0 does not provide the function xdebug_is_enabled anymore. See https://xdebug.org/docs/upgrade_guide#Changes-to-Functions

How to reproduce
You can use the reproducer from #30571. Please ensure your environment has Xdebug 3.0 installed.

Possible Solution
Replace \function_exists('xdebug_is_enabled') && xdebug_is_enabled() in AutowiringFailedException.php:26 with a condition which is true for xdebug 2.x and 3.x.

Additional context

Exception call stack:
(Hint: The mentioned class@anonymous::__toString() is defined in symfony/dependency-injection/Exception/AutowiringFailedException.php:39 and following)

PHP Fatal error:  Method class@anonymous::__toString() must not throw an exception, caught Symfony\Component\DependencyInjection\Exception\AutowiringFailedException:  in /app/app/vendor/symfony/dependency-injection/Compiler/AutowirePass.php on line 236
PHP Stack trace:
PHP   1. {main}() /app/app/bin/console:0
PHP   2. Symfony\Bundle\FrameworkBundle\Console\Application->run() /app/app/bin/console:42
PHP   3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /app/app/vendor/symfony/console/Application.php:142
PHP   4. Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() /app/app/vendor/symfony/framework-bundle/Console/Application.php:74
PHP   5. App\Kernel->boot() /app/app/vendor/symfony/framework-bundle/Console/Application.php:168
PHP   6. App\Kernel->initializeContainer() /app/app/vendor/symfony/http-kernel/Kernel.php:131
PHP   7. Symfony\Component\DependencyInjection\ContainerBuilder->compile() /app/app/vendor/symfony/http-kernel/Kernel.php:533
PHP   8. Symfony\Component\DependencyInjection\Compiler\Compiler->compile() /app/app/vendor/symfony/dependency-injection/ContainerBuilder.php:736
PHP   9. Symfony\Component\DependencyInjection\Compiler\AutowirePass->process() /app/app/vendor/symfony/dependency-injection/Compiler/Compiler.php:91
PHP  10. Symfony\Component\DependencyInjection\Compiler\AutowirePass->process() /app/app/vendor/symfony/dependency-injection/Compiler/AutowirePass.php:54
PHP  11. Symfony\Component\DependencyInjection\Compiler\AutowirePass->processValue() /app/app/vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php:46
PHP  12. Symfony\Component\DependencyInjection\Compiler\AutowirePass->doProcessValue() /app/app/vendor/symfony/dependency-injection/Compiler/AutowirePass.php:72
PHP  13. Symfony\Component\DependencyInjection\Compiler\AutowirePass->processValue() /app/app/vendor/symfony/dependency-injection/Compiler/AutowirePass.php:103
PHP  14. Symfony\Component\DependencyInjection\Compiler\AutowirePass->processValue() /app/app/vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php:81
PHP  15. Symfony\Component\DependencyInjection\Compiler\AutowirePass->doProcessValue() /app/app/vendor/symfony/dependency-injection/Compiler/AutowirePass.php:72
PHP  16. Symfony\Component\DependencyInjection\Compiler\AutowirePass->autowireCalls() /app/app/vendor/symfony/dependency-injection/Compiler/AutowirePass.php:126
PHP  17. Symfony\Component\DependencyInjection\Compiler\AutowirePass->autowireMethod() /app/app/vendor/symfony/dependency-injection/Compiler/AutowirePass.php:171
PHP  18. Symfony\Component\DependencyInjection\Compiler\AutowirePass->Symfony\Component\DependencyInjection\Compiler\{closure:/app/app/vendor/symfony/dependency-injection/Compiler/AutowirePass.php:229-241}() /app/app/vendor/symfony/dependency-injection/Compiler/AutowirePass.php:261
@nicolas-grekas
Copy link
Member

Replace \function_exists('xdebug_is_enabled') && xdebug_is_enabled() in AutowiringFailedException

would you like giving this a try and sending a PR?

@stof
Copy link
Member

stof commented Nov 27, 2020

the issue I see is that xdebug_disable() is also gone in Xdebug 3. As the workaround was to use it to disable Xdebug, there is no equivalent in Xdebug 3.

But the fact that we need to disable Xdebug for things to work seems to indicate that Xdebug is changing the behavior of PHP there. So I think this should better be fixed in Xdebug than trying to use a different workaround in Symfony (if there is one)

@ericpoe
Copy link

ericpoe commented Nov 27, 2020

Derick suggests contacting him via email for a potential workaround https://bugs.xdebug.org/view.php?id=1883#c5516

@ericpoe
Copy link

ericpoe commented Nov 28, 2020

A manual workaround that I've found, for now, is to turn off xdebug for building the cache and then turn it back on.

export XDEBUG_MODE=off
bin/console cache:clear
export XDEBUG_MODE=debug,develop // or whatever you use

@ishyevandro
Copy link

Version 4.4.16 affected too.

@vertexvaar
Copy link
Contributor Author

@ishyevandro wrote:

Version 4.4.16 affected too.

I created the PR against Branch 4.4, so it will be fixed there and merged into 5.1 😉

@ericpoe wrote:

Derick suggests contacting him via email for a potential workaround https://bugs.xdebug.org/view.php?id=1883#c5516

I tried to create a minimal reproducer but didn't succeed. I will try again when i get to it. (/cc @derickr)

@stof wrote:

But the fact that we need to disable Xdebug for things to work seems to indicate that Xdebug is changing the behavior of PHP there. So I think this should better be fixed in Xdebug than trying to use a different workaround in Symfony (if there is one)

I completely agree, however i am certain that this fix will reach symfony users faster than the bugfix in xdebug (which is affected in version 2 and 3).

andreluizmachado pushed a commit to oat-sa/simple-roster that referenced this issue Dec 1, 2020
There is a bug on symfony which is not compatible with the new xdebug
version

Refs: symfony/symfony#39195
@ericpoe
Copy link

ericpoe commented Dec 3, 2020

A manual workaround that I've found, for now, is to turn off xdebug for building the cache and then turn it back on.

export XDEBUG_MODE=off
bin/console cache:clear
export XDEBUG_MODE=debug,develop // or whatever you use

An even easier way:

XDEBUG_MODE=off bin/console cache:clear

nicolas-grekas added a commit that referenced this issue Dec 8, 2020
This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[DI] Fix Xdebug 3.0 detection

| Q             | A
| ------------- | ---
| Branch?       | 4.4 (for bug fixes)
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #39195
| License       | MIT
| Doc PR        | n/a

Xdebug 3.0 removed the function `xdebug_is_enabled()`. To detect if Xdebug 3.0 is installed (it doesn't even need to be enabled to reproduce the bug) i added `function_exists('xdebug_info')`. AFAIS `xdebug_info()` is available in Xdebug >= 3.0 only.

Commits
-------

38f8edd [DI] Fix Xdebug 3.0 detection
dayllanmaza added a commit to wikimedia/ws-export that referenced this issue Dec 17, 2020
dayllanmaza added a commit to wikimedia/ws-export that referenced this issue Dec 17, 2020
dayllanmaza added a commit to wikimedia/ws-export that referenced this issue Dec 17, 2020
MusikAnimal pushed a commit to wikimedia/ws-export that referenced this issue Dec 18, 2020
cimurah pushed a commit to wikimedia/ws-export that referenced this issue May 17, 2022
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

7 participants