Skip to content

Nullable collections throw RuntimeException #163

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

Closed
vudaltsov opened this issue Apr 4, 2022 · 1 comment · Fixed by #168
Closed

Nullable collections throw RuntimeException #163

vudaltsov opened this issue Apr 4, 2022 · 1 comment · Fixed by #168

Comments

@vudaltsov
Copy link

The following code throws ?array is not a collection:

(new TypeResolver())->resolve('?array<string, int>')
@hemberger
Copy link
Contributor

See also phpDocumentor/phpDocumentor#3290.

hemberger added a commit to hemberger/TypeResolver that referenced this issue Jul 28, 2022
Fixes phpDocumentor#163.
Fixes phpDocumentor/phpDocumentor#3290.

Shorthand nullable type syntax is now supported for collection types
(e.g. `?array<int>`).

This also prevents a misuse of the shorthand nullable type syntax with
compound types, which is illegal with PHP types. This is documented in
the Union Types 2.0 RFC (https://wiki.php.net/rfc/union_types_v2) by
N. Popov:

> Union types and the ?T nullable type notation cannot be mixed.
> Writing ?T1|T2, T1|?T2 or ?(T1|T2) is not supported and T1|T2|null
> needs to be used instead.
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

Successfully merging a pull request may close this issue.

2 participants