Skip to content

Support phpstan/phpdoc-parser v2 #29

Description

@mesilov

Problem

typhoon/reflection currently requires phpstan/phpdoc-parser ^1.21 in both 0.4.4 and 0.5.x-dev.

Projects that upgrade their tooling to PHPStan 2 / Rector 2 can end up with phpstan/phpdoc-parser v2 loaded in the same PHP process. In that case Typhoon Reflection still instantiates the v1 API:

private readonly Lexer $lexer = new Lexer(),

but phpdoc-parser v2 requires ParserConfig in PHPStan\PhpDocParser\Lexer\Lexer::__construct().

This causes runtime failures such as:

ArgumentCountError: Too few arguments to function PHPStan\PhpDocParser\Lexer\Lexer::__construct(), 0 passed in vendor/typhoon/reflection/Internal/PhpDoc/PhpDocParser.php on line 30 and exactly 1 expected

In our case this happened after upgrading bitrix24/b24phpsdk to PHPStan 2 and Rector 2. Rector 2 registers a Composer autoload file and, under PHPUnit 12, can preload its bundled phpdoc-parser v2 before project code that uses Typhoon Reflection.

Reproduction context

Proposed solution

Add support for phpstan/phpdoc-parser ^2, or provide a compatibility layer that constructs parser services differently depending on the installed parser version.

At minimum, it would help to know whether v2 support is planned for 0.5.x.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions