Skip to content

Node visitors trigger "might add a native return type" deprecations of Symfony's DebugClassLoader #243

Closed
goaop/framework
#784

Description

@lisachenko

Problem

PhpParser\NodeVisitor declares the return types of its methods in docblocks only (@return null|Node[], @return null|int|Node|Node[]). Three visitors override them with neither a native return type nor their own @return (just {@inheritDoc}):

  • src/NodeVisitor/RootNamespaceNormalizer.php — beforeTraverse(array $nodes)
  • src/NodeVisitor/GeneratorDetector.php — enterNode(Node $node)
  • src/NodeVisitor/StaticVariablesCollector.php — enterNode(Node $node)

Symfony's DebugClassLoader (debug mode of every Symfony application) reports a deprecation when such a class loads, e.g.:

Method "PhpParser\NodeVisitor::beforeTraverse()" might add "?array" as a native return type declaration in the future.
Do the same in implementation "Go\ParserReflection\NodeVisitor\RootNamespaceNormalizer" now to avoid errors or add an
explicit @return annotation to suppress this message.

This shows up in goaop/goaop-symfony-bundle whenever weaving runs under the DebugClassLoader (found while working on goaop/goaop-symfony-bundle#23).

What silences it

Checked with Symfony 8.1 DebugClassLoader and PHP-Parser 5.9 against a NodeVisitorAbstract subclass:

Variant of beforeTraverse(array $nodes) Deprecation
{@inheritdoc} docblock, no return type (current) yes
no docblock yes
#[\ReturnTypeWillChange] yes
explicit @return null|\PhpParser\Node[] docblock no
native : ?array no

DebugClassLoader reports the method when it has no native return type and no @return tag of its own. {@inheritdoc} carries no @return, and #[\ReturnTypeWillChange] only applies to PHP's own tentative types of internal classes.

Decision

Explicit @return docblocks, no native return types: PHP-Parser owns these signatures and may declare native types itself in a future version, so this library shouldn't commit to them. Fix on 4.x; it flows into master through the cascade merge.

Activity

  1. lisachenko commented on Nov 2, 2026

    @lisachenko
    MemberAuthor

    Fixed by #245, merged into 4.x and carried into master by the cascade PR #250. GitHub didn't close this automatically because #245 targeted 4.x, not the default branch.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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