diff --git a/website/src/writing-php-code/phpdoc-types.md b/website/src/writing-php-code/phpdoc-types.md index 77beb42444..0e166f6563 100644 --- a/website/src/writing-php-code/phpdoc-types.md +++ b/website/src/writing-php-code/phpdoc-types.md @@ -157,6 +157,7 @@ Conditional return types A simpler alternative to generics if you just want to infer the return type based on if-else logic. + ```php /** * @return ($size is positive-int ? non-empty-array : array) @@ -181,6 +182,14 @@ public function fetch(int|array $id) } ``` +Utility types for generics +------------------------- + +`template-type` can be used to [get `@template` type from a passed object argument](https://phpstan.org/r/ceb59974-0a7c-492a-867a-5d5b7c30e52f). Related discussion [here](https://github.com/phpstan/phpstan/discussions/9053). + +`new` can be used to [create an object type from a class-string type](https://phpstan.org/r/a01e1e49-6f05-43a8-aac7-aded770cd88a). + + class-string -------------------------