renakdup / simple-dic

🔥 Simple DIC - PHP DI Container with autowiring in a single file allows you to easily use it in your PHP applications and especially convenient for WordPress plugins and themes.
https://github.com/renakdup/simple-php-dic
MIT License
7 stars 1 forks source link

Add generic type for $c->get method #18

Open renakdup opened 3 months ago

renakdup commented 3 months ago

https://phpstan.org/blog/generics-by-examples#function-accepts-any-string%2C-but-returns-object-of-the-same-type-if-it%E2%80%99s-a-class-string

Generics could not be applied because we use as classes and as string types as well. So due to that in case of using combining types it would not work, and we get an error

image

due to type normalizing. And in case we use just class-string and returning type T it works for classes but doesn't work for string in $c->get('string-service') in case we use primitives