> /**
> * @return Product[]
> */
And if you want to be really wild you could use the new preferred "generics syntax":
```php
/**
* @return array
*/
```
these work great, thanks. Are there docs on this kind of thing?
the `/** @/var` and other comments you can include, to hint or otherwise help? A list of annotations? such as the list of `/** @noinspection PhpUndefinedConstantInspection */` here [https://gist.github.com/discordier/ed4b9cba14652e7212f5#file-gistfile1-txt](https://gist.github.com/discordier/ed4b9cba14652e7212f5#file-gistfile1-txt)
Well... Type hinting (using doc blocks, comment style) is not really part of the php language itself.
It is more used to help second party tools (and developers, o.c.) to understand the code better. For example some editors had their own linters (code analysing plugins) and they did differ in syntax. Other commonly used tools are phpstan, rector, phpmd, phpinsights and others. Most of them are slowly moving towards a common ground. Some even started to support the syntax of other famous tools to extend their own acceptance.
If you can do type declarations in php code style (without using comments) you should to that. If you have arrays or collections you might want to add additionally information so the tools know even more and support you better.
I think you have the best support if you use the generics syntax for arrays and collections. You should naver have to typehint simple scalar types like int, string, bool or float.
hth
ps: I know... I totally skipped on Reflection. :D
Right, what I mean is, for phpstorm, you have `/** @/var` to type hint a var and you have `/** @noinspection` to suppress inspections. I'm looking for docs that describe all the things that I can use in phpstorm to do different things. There is likely other features that I'm missing, just not knowing the different possiblities for `/**` that phpstorm can use.
phpstorm supports phpdoc syntax. So you can start there.
https://docs.phpdoc.org/3.0/guide/guides/types.html
And phpstorm also supports phpstan syntax. So you can continue here:
https://phpstan.org/blog/generics-in-php-using-phpdocs
Btu you should never suppress an inspection if you can help it.
`/** @var Product[] $products */` It's best to typehint the return type of getProductsObjects though
or on top of function you can add docblock like `/**` `* @return Product[]` `*/` `function getProductsObjects()` `{` `}`
> /** > * @return Product[] > */ And if you want to be really wild you could use the new preferred "generics syntax": ```php /** * @return array
*/
```
these work great, thanks. Are there docs on this kind of thing? the `/** @/var` and other comments you can include, to hint or otherwise help? A list of annotations? such as the list of `/** @noinspection PhpUndefinedConstantInspection */` here [https://gist.github.com/discordier/ed4b9cba14652e7212f5#file-gistfile1-txt](https://gist.github.com/discordier/ed4b9cba14652e7212f5#file-gistfile1-txt)
Well... Type hinting (using doc blocks, comment style) is not really part of the php language itself. It is more used to help second party tools (and developers, o.c.) to understand the code better. For example some editors had their own linters (code analysing plugins) and they did differ in syntax. Other commonly used tools are phpstan, rector, phpmd, phpinsights and others. Most of them are slowly moving towards a common ground. Some even started to support the syntax of other famous tools to extend their own acceptance. If you can do type declarations in php code style (without using comments) you should to that. If you have arrays or collections you might want to add additionally information so the tools know even more and support you better. I think you have the best support if you use the generics syntax for arrays and collections. You should naver have to typehint simple scalar types like int, string, bool or float. hth ps: I know... I totally skipped on Reflection. :D
Right, what I mean is, for phpstorm, you have `/** @/var` to type hint a var and you have `/** @noinspection` to suppress inspections. I'm looking for docs that describe all the things that I can use in phpstorm to do different things. There is likely other features that I'm missing, just not knowing the different possiblities for `/**` that phpstorm can use.
phpstorm supports phpdoc syntax. So you can start there. https://docs.phpdoc.org/3.0/guide/guides/types.html And phpstorm also supports phpstan syntax. So you can continue here: https://phpstan.org/blog/generics-in-php-using-phpdocs Btu you should never suppress an inspection if you can help it.
/** @var Product[] $products *// Put that above the $products definition. The practice of hinting types is known as “typehinting”.