Skip to content

How to param/return class<T> or null with generics #10238

Closed Answered by ondrejmirtes
darthf1 asked this question in Support
Discussion options

You must be logged in to vote

Yeah, right now PHPStan does not understand what you're trying to say with this constructor parameter: (T is null ? null : DomainEventMetadata<T>)

There's no PHPDoc tag to instruct PHPStan "infer T as something when doing new Foo()".

What I tried for your example is a "null object" pattern. Basically don't have null in your code but treat "exists" and "does not exist" scenario the same way from the interface PoV: https://phpstan.org/r/640316e7-ab4f-4366-a1ff-734646f15268

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by darthf1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet
2 participants