Skip to content

Commit

Permalink
Update phpdoc-types.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 6, 2024
1 parent 41394d8 commit f2b6922
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions website/src/writing-php-code/phpdoc-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
-------------------------

Expand Down

0 comments on commit f2b6922

Please sign in to comment.