phpro / grumphp-shim

This repository provides easy way to install GrumPHP without the risk of conflicting dependencies.
MIT License
22 stars 3 forks source link

Cannot declare interface Stringable, because the name is already in use #5

Closed nicrodgers closed 4 years ago

nicrodgers commented 4 years ago

I get this error when trying to composer require phpro/grumphp-shim

PHP Warning: Cannot declare interface Stringable, because the name is already in use in phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/polyfill-php80/Resources/stubs/Stringable.php on line 12 PHP Stack trace: PHP 1. {main}() /app/vendor/phpro/grumphp-shim/grumphp.phar:0

but it does install ok, and I don't see the error again when running grumphp. Everything seems to work ok.

veewee commented 4 years ago

Can you paste your composer file and steps to reproduce the error?

nicrodgers commented 4 years ago

It's on a project with a pretty huge composer file. I'll see if I can create an example with a minimal amount of projects required.

nicrodgers commented 4 years ago

Here we go - was easier than I thought :)

composer.json:

{
    "require": {
        "mglaman/drupal-check": "^1.1",
        "phpro/grumphp-shim": "^0.19.0"
    }
}

steps to reproduce:

result: PHP warning is displayed Warning: Cannot declare interface Stringable, because the name is already in use in phar:///Volumes/www/sandbox/grumphp/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/polyfill-php80/Resources/stubs/Stringable.php on line 12

Maybe I need to a file a bug on the PHPStan project instead? Let me know what you think. Thanks.

veewee commented 4 years ago

It looks more like a PHPStan issue:

First it makes sure composer always loads the phpstan bootstrap file: https://github.com/phpstan/phpstan/blob/master/composer.json#L21

Next, it registers an autoloader that only works inside phars (which grumphp-shim is) https://github.com/phpstan/phpstan/blob/master/bootstrap.php This is most likely under the assumption that it only runs for phpstan?

The phpstan package also contain the php-80 stubs, so that is why you are seeing the Warning. It is indeed not blocking, but still a bit strange.

GrumPHP will always try to load the project specific autoloader to make sure local classes can be loaded as well.

nicrodgers commented 4 years ago

Thanks for looking in to this and providing such comprehensive feedback so quickly! I'll raise an issue with the phpstan team.

nicrodgers commented 4 years ago

Just posting the link to the phpstan issue for anyone who might land on this in the future: https://github.com/phpstan/phpstan/issues/3457