Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared shape definition for union of object and array #187

Open
johnbillion opened this issue Apr 19, 2023 · 0 comments
Open

Shared shape definition for union of object and array #187

johnbillion opened this issue Apr 19, 2023 · 0 comments

Comments

@johnbillion
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant