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
tl;dr:
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:
If the shape could be used for a union of
object|array
it would avoid this duplication.