Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

rfc recursive return type definitions #9

Open
@SignpostMarv

Description

/**
* @return array<string, scalar|array<int, array<{{recursive definition is here}}>>>
*/
function DoThingWithNode(DOMNode $node) : array { /* do stuff here */ }

So I have this method that return an array with string keys whose values are either scalars or arrays with string keys whose values are either scalars or arrays with string keys whose values are either scalars with string keys..... etc.

If the definition stops at array, then one would just assume that phpstan et. al would determine that values at that level are "mixed" (or otherwise defined), which may be an undesirable effect.

One solution to the recursive @return/@param problem could be to define a class that encapsulates the recursion- i.e. class Thing extends ArrayObject & modify the return types to indicate scalar|Thing, but I'd be wanting to avoid class definitions.

A docblock-type solution would be to define a template/pattern tag so one could @thing foo array<string, scalar|array<string, {{@thing foo}}> , but I could foresee problems by virtue of it being a recursive solution to a recursive problem.

Thoughts?

p.s. the recursion here comes from the return type possibly containing arrays of the return type of the method, so maybe @return array<string, scalar|{{@method DoThingWithNode}}||{{@method DoSomeOtherThingWithNode}}> might be a solution by explicitly indicating the return values is built up from other methods ?

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

        AltStyle によって変換されたページ (->オリジナル) /