Skip to content
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

DebugClassLoader fails with Symfony's BC layers #42303

Closed
ostrolucky opened this issue Jul 28, 2021 · 11 comments
Closed

DebugClassLoader fails with Symfony's BC layers #42303

ostrolucky opened this issue Jul 28, 2021 · 11 comments

Comments

@ostrolucky
Copy link
Contributor

ostrolucky commented Jul 28, 2021

Symfony version(s) affected: 5.3.5

Description
These kind of "BC layers" don't work in combination with Symfony's DebugClassLoader

trigger_deprecation('symfony/messenger', '5.1', 'The "%s" class is deprecated, use "%s" instead. The Doctrine transport has been moved to package "symfony/doctrine-messenger" and will not be included by default in 6.0. Run "composer require symfony/doctrine-messenger".', DoctrineTransportFactory::class, BridgeDoctrineTransportFactory::class);

class_exists(BridgeDoctrineTransportFactory::class);

if (false) {
    /**
     * @deprecated since Symfony 5.1, to be removed in 6.0. Use symfony/doctrine-messenger instead.
     */
    class DoctrineTransportFactory
    {
    }
}

How to reproduce

<?php

use Symfony\Component\ErrorHandler\DebugClassLoader;
use Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory;

require __DIR__.'/vendor/autoload.php';

DebugClassLoader::enable();
class_exists(DoctrineTransportFactory::class);

produces

PHP Fatal error:  Uncaught RuntimeException: The autoloader expected class "Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory" to be defined in file "/Users/gabriel.ostrolucky/Documents/CraueGeoBundle/vendor/composer/../symfony/symfony/src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineTransportFactory.php". The file was found but the class was not in it, the class name or namespace probably has a typo. in /Users/gabriel.ostrolucky/Documents/CraueGeoBundle/vendor/symfony/symfony/src/Symfony/Component/ErrorHandler/DebugClassLoader.php:403
Stack trace:
#0 /Users/gabriel.ostrolucky/Documents/CraueGeoBundle/vendor/symfony/symfony/src/Symfony/Component/ErrorHandler/DebugClassLoader.php(360): Symfony\Component\ErrorHandler\DebugClassLoader->checkClass('Symfony\\Compone...', '/Users/gabriel....')
#1 [internal function]: Symfony\Component\ErrorHandler\DebugClassLoader->loadClass('Symfony\\Compone...')
#2 /Users/gabriel.ostrolucky/Documents/CraueGeoBundle/test.php(9): class_exists('Symfony\\Compone...')
#3 {main}
  thrown in /Users/gabriel.ostrolucky/Documents/CraueGeoBundle/vendor/symfony/symfony/src/Symfony/Component/ErrorHandler/DebugClassLoader.php on line 403

Fatal error: Uncaught RuntimeException: The autoloader expected class "Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory" to be defined in file "/Users/gabriel.ostrolucky/Documents/CraueGeoBundle/vendor/composer/../symfony/symfony/src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineTransportFactory.php". The file was found but the class was not in it, the class name or namespace probably has a typo. in /Users/gabriel.ostrolucky/Documents/CraueGeoBundle/vendor/symfony/symfony/src/Symfony/Component/ErrorHandler/DebugClassLoader.php:403
Stack trace:
#0 /Users/gabriel.ostrolucky/Documents/CraueGeoBundle/vendor/symfony/symfony/src/Symfony/Component/ErrorHandler/DebugClassLoader.php(360): Symfony\Component\ErrorHandler\DebugClassLoader->checkClass('Symfony\\Compone...', '/Users/gabriel....')
#1 [internal function]: Symfony\Component\ErrorHandler\DebugClassLoader->loadClass('Symfony\\Compone...')
#2 /Users/gabriel.ostrolucky/Documents/CraueGeoBundle/test.php(9): class_exists('Symfony\\Compone...')
#3 {main}
  thrown in /Users/gabriel.ostrolucky/Documents/CraueGeoBundle/vendor/symfony/symfony/src/Symfony/Component/ErrorHandler/DebugClassLoader.php on line 403

Possible Solution

Additional context
ref: doctrine/DoctrineBundle#1373

@Nyholm
Copy link
Member

Nyholm commented Aug 1, 2021

Thank you for this issue.

I cannot reproduce this. Could you help me with a commit or PR to https://github.com/Nyholm/sf-issue-42303?

@ostrolucky
Copy link
Contributor Author

ostrolucky commented Aug 1, 2021

I don't quite understand why is this making a difference, but bug is reproducible when using symfony/symfony instead of symfony/messenger. I've pushed a commit.

edit: Ah right, symfony/messenger requires symfony/doctrine-messenger, but symfony/symfony doesn't

@Nyholm
Copy link
Member

Nyholm commented Aug 2, 2021

When I test with "symfony/symfony": "5.3.x-dev" then I cannot reproduce the error. That means it will be fixed in the next patch release.

I have not looked for the commit that fixed the issue. Can you confirm that "symfony/symfony": "5.3.x-dev" is working for you too?

@ostrolucky
Copy link
Contributor Author

You can't reproduce with commit I pushed now? I still get same error with 5.3.x-dev

@encreinformatique
Copy link

I run into a similar problem upgrading from 5.2.9 to 5.3.6.

The autoloader expected class "Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory" to be defined in file "/var/www/docker-install/vendor/composer/../symfony/symfony/src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineTransportFactory.php". The file was found but the class was not in it, the class name or namespace probably has a typo.

@ostrolucky puts me in the right track stating that "Ah right, symfony/messenger requires symfony/doctrine-messenger, but symfony/symfony doesn't". The app is still requiring symfony/symfony (It is an old project coming a long way from Sf 2.1) but does not require directly symfony/messenger.

Adding symfony/doctrine-messenger to the dependencies made the error disappear and it is back on track on dev environment.

PS : thank you @ostrolucky !!

@craue
Copy link
Contributor

craue commented Aug 12, 2021

Any news on this? It's still an issue for me.

@wouterj
Copy link
Member

wouterj commented Aug 12, 2021

If I understand correctly, this is only an issue when using the symfony/symfony package. In that case, the solution is simple: Don't use symfony/symfony.
This package is by all means deprecated and it will likely no longer get versions in 6.0. Require each Symfony bundle and component separately if you need them (optionally using Symfony Flex, but you can also do it without Flex).

@craue
Copy link
Contributor

craue commented Aug 12, 2021

Alright then. Thanks.

@ostrolucky
Copy link
Contributor Author

It isn't deprecated (yet). It's still being updated and isn't marked as abandoned, nor no official announcement was posted about this AFAIK.

@nicolas-grekas
Copy link
Member

I'm not sure why this happens only when using symfony/symfony, but the solution is to not use it. Not sure it's worth more of maintainers' time. Closing therefor.

@nicolas-grekas
Copy link
Member

I submitted #45563 to deprecate requiring symfony/symfony.

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

9 participants