Skip to content

PHPStan throws fatal exception when run with other dependencies that bring in nikic/php-parser #3237

@tspencer244

Description

@tspencer244

Bug report

PHPStan version: 0.12.20
PHP version: 7.4.5
Composer version: 1.10.5

Unable to run the latest release of phpstan when another package that provides nikic/php-parser is present

Code snippet that reproduces the problem

mkdir project-root \
  && cd project-root \
  && composer init -n \
  && composer require --dev phpstan/phpstan phpmetrics/phpmetrics \
  && vendor/bin/phpstan

Output:

Using version ^0.12.20 for phpstan/phpstan
Using version ^2.6 for phpmetrics/phpmetrics
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 3 installs, 0 updates, 0 removals
  - Installing phpstan/phpstan (0.12.20): Loading from cache
  - Installing nikic/php-parser (v4.4.0): Loading from cache
  - Installing phpmetrics/phpmetrics (v2.6.2): Loading from cache
Writing lock file
Generating autoload files
1 package you are using is looking for funding.
Use the `composer fund` command to find out more!
PHP Fatal error:  Cannot declare class PhpParser\NodeVisitorAbstract, because the name is already in use in phar:///project-root/vendor/phpstan/phpstan/phpstan/vendor/nikic/php-parser/lib/PhpParser/NodeVisitorAbstract.php on line 9
Fatal error: Cannot declare class PhpParser\NodeVisitorAbstract, because the name is already in use in phar:///project-root/vendor/phpstan/phpstan/phpstan/vendor/nikic/php-parser/lib/PhpParser/NodeVisitorAbstract.php on line 9

Expected output

I expect the command to run and display available usages or help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions