You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/*** @return array<string, scalar|array<int, array<{{recursive definition is here}}>>>*/functionDoThingWithNode(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 ?
The text was updated successfully, but these errors were encountered:
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 indicatescalar|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 ?The text was updated successfully, but these errors were encountered: