4
votes

After running composer update , I keep having the error below:

Warning: Ambiguous class resolution, "Doctrine\ORM\Persisters\Entity\BasicEntityPersister" was found in both "$baseDir . '/engine/Library/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php" and "/var/www/html/shop5/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php", the first will be used. Warning: Ambiguous class resolution, "Doctrine\Common\Proxy\AbstractProxyFactory" was found in both "$baseDir . '/engine/Library/Doctrine/Common/Proxy/AbstractProxyFactory.php" and "/var/www/html/shop5/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php", the first will be used.

I have tried to run the following commands but none of them works:

composer dump-autoload -o
composer clearcache

Any idea how to fix this issue ? Thank you

[shopware5 - php7.0]

2
Looks like you have the Doctrine library installed in multiple places, which one are you using? Try to delete the location that you're not using. - Nando

2 Answers

3
votes

This is the normal behavior of Shopware.

The Doctrine library uses the final class statement quite often and in order to get it to work with the Shopware attribute system the classes were replaced through the composer autoloading. You can find the changed files in shopware/engine/Library/Doctrine/Common

FYI: This is the reason why Shopware only works when the composer autoloading is optimized.

composer dump-autoload --optimize

Otherwiese you will encounter random errors from invalid or wrong entities.

2
votes

To get rid of these warning you should add files with ambiguous classes to exclude-from-classmap in your composer.json:

"autoload": {
    ...
    "exclude-from-classmap": [
        ...
        "vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php",
        "vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php"
    ]
},

Then dump-autoload will ignore these files.


This is the reason why Shopware only works when the composer autoloading is optimized.

I didn't investigate how this is done in Shopware, but this also could be fixed/improved. For composer more precise definitions for namespaces have a precedence. So if you have this in your autoload:

"autoload": {
    "psr-0": { 
        "somevendor\\somepackage\\": "vendor/somevendor/somepackage/",
        "somevendor\\somepackage\\db\\": "overrides/somevendor/somepackage/db/"
    }
},

And if you request for somevendor\somepackage\db\Entity class, the composer will first search in overrides/somevendor/somepackage/db/Entity.php and only if it can't find it, it will try vendor/somevendor/somepackage/db/Entity.php. This is because definition for somevendor\somepackage\db namespace is more precise than for somevendor\somepackage.

So if you want to override 3rd-party classes in this way, you should define more precise namespaces than 3rd-party library do.