Show Menu
Cheatography

Psalm PHP Cheat Sheet (DRAFT) by

Cheat sheet for PHP type hinting using Psalm (or PHPStan)

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Scalar types

bool
Boolean
float
Float
string
String
int
Integer
int<-1, 3>
Range of integers -1 through 3
int<min, 0>
Use
min
for
PHP_IN­T_MIN
int<0, max>
Use
max
for
PHP_IN­T_MAX
int-ma­sk<1, 2, 4>
Bitmask combin­ation of its parameters (corre­sponds to
0|1|2|­3|4­|5|6|7
)
int-ma­sk-­of<­Cla­ss:­:CO­NST­ANT­_*>
Correspond to
0|1|2|­3|4­|5|6|7
if there are three constants
CONSTA­NT_­{A,B,C}
with values
1
,
2
and
4
.
array-key
Supertype (not a union) of
int
and
string
numeric
Supertype of
int
or
float
or
numeri­c-s­tring
class-­string
Expect a class string
::class
class-­str­ing­<My­Cla­ss>
Expects a specific class string
MyClas­s::­class
interf­ace­-string
Similar to class-­string, but expects interf­ace(s)
trait-­string
Similar to class-­string, but expects trait(s)
enum-s­tring
Similar to class-­string, but expects enum(s)
callab­le-­string
Denotes a string value that has passed an
is_cal­lable
check
numeri­c-s­tring
Denotes a string value that has passed an is_numeric check
litera­l-s­tring
Denotes a string value that is entirely composed of strings
litera­l-int
Denotes an int value that is entirely composed of literal integers in your applic­ation
lowerc­ase­-string
Lowercase string
non-em­pty­-string
String that is not empty
non-em­pty­-lo­wer­cas­e-s­tring
String that is not empty AND lowercase

Property declar­ation types

@var string­|null
Indicates property is a string or null
@var string $a
Indicates variable $a is a string
@param 'a'|'b' $s
Param $s is "­a" or "­b"
@param A::FOO | A::BAR $s
Param $s is const
A::FOO
or
A::BAR
@param A::STA­TUS_* $s
Param $s is any const of
A
prefixed with
STATUS_