Shared shape definition for union of object and array
johnbillion opened this issue · 2 comments
tl;dr:
(object|array){ foo: int, bar: string }
Several function parameters in WordPress can be passed as an associative array or a stdClass. This is an unfortunate result of some legacy functions casting arrays to objects with (object) $array.
The object shape support added in PHPStan 1.10.12 is helpful in this regard, thank you for working on it. It would be great if a shape could be shared in an object and array union to avoid duplicating all the elements of the shape.
Here's how such a parameter can be documented now:
@phpstan-param object{
foo: int,
bar: string,
baz: bool,
}|array{
foo: int,
bar: string,
baz: bool,
} $args
If the shape could be used for a union of object|array it would avoid this duplication.
@phpstan-param (object|array){
foo: int,
bar: string,
baz: bool,
} $args
Err, no :) Just repeat it in a union.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.