From f2b69220b7c8b93a17300abcb57a842cbd72b7ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Mirtes?= Date: Mon, 6 May 2024 14:55:48 +0200 Subject: [PATCH] Update phpdoc-types.md --- website/src/writing-php-code/phpdoc-types.md | 9 +++++++++ 1 file changed, 9 insertions(+) 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 -------------------------