Skip to content

[PHP8.6] ReflectionParameter::getDocComment() — parameter doc comments #221

Closed

Description

@lisachenko

Part of epic #219.

Feature

PHP 8.6 allows doc comments directly on function/method parameters, exposed via the new native ReflectionParameter::getDocComment(): string|false:

function store(
    /** @param Book[] */
    array $books,
): void {}

Scope

  • Implement getDocComment() in src/ReflectionParameter.php by reading the doc comment attached to the parameter's AST node (PhpParser\Node\Param), returning false when absent — matching native semantics exactly (including promoted constructor properties).
  • Add tests/Stub/FileWithParameters86.php (or similarly named per-feature stub) with parameters carrying doc comments in various positions: plain params, promoted params, variadic, by-ref, attributes + doc comment combined.
  • Parity tests in tests/ReflectionParameterTest.php: static result must equal native reflection when running on PHP >= 8.6 (guard with PHP_VERSION_ID); on 8.5 assert the statically-derived values directly.
  • Verify PHP-Parser attaches the doc comment to the Param node in current releases; if it does not, document the limitation and test what is achievable.

Acceptance criteria

  • getDocComment() returns the exact doc block text or false, matching native output byte-for-byte on 8.6.
  • PHPUnit green on 8.5, PHPStan level 10 clean.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions