Overview
Comparison
Every construct below is fed to the parser of each tool, asked directly. The table lists the basic constructs all of them read the same way and those on which they differ. Only the syntax is compared: whether the named type exists is not.
| Sign | Constructs | Malformed input |
|---|---|---|
| ✓ | read as written | rejected |
| ✗ | rejected | accepted |
| ! | accepted, but the meaning changed (a word dropped, words glued together, a value clamped) | accepted, meaning changed |
| PHPStan | Psalm | TypeLang | |
|---|---|---|---|
| Constructs read as written | 180/239 | 108/239 | 236/239 |
| Malformed inputs rejected | 29/34 | 5/34 | 33/34 |
Methodology
Section titled “Methodology”| Tool | Version | A type is supported when |
|---|---|---|
| PHPStan | phpstan/phpdoc-parser 2.4 |
TypeParser::parse() reads the source whole, leaving no trailing input |
| Psalm | vimeo/psalm 7.0 |
Psalm\Type::parseString() returns a type carrying what was written |
| TypeLang | type-lang/parser 2.0 |
TypeParser::parse() returns a node, every feature of the parser enabled |
The tools run with their default settings. Psalm is given the templates
T U V K K2 L and the parameters $a $b, otherwise it cannot read T[K] and
conditional types at all. Error messages, offsets and the error-tolerant mode
have no counterpart in the other tools and are not compared.
Class names, pseudo types and $this.
| PHPStan | Psalm | TypeLang | |
|---|---|---|---|
| supported | 8/8 | 5/8 | 8/8 |
\Foo\Bar |
✓ | ✓ | ✓ |
non-empty-string |
✓ | ✓ | ✓ |
array-key |
✓ | ✓ | ✓ |
positive-int |
✓ | ✓ | ✓ |
namespace\Foo |
✓ | ✓ | ✓ |
Foo-bar |
✓ | ✗ 1 | ✓ |
$this |
✓ | ! 2 | ✓ |
?$this |
✓ | ! 2 | ✓ |
- PHPStan allows it anywhere, Psalm only for known pseudo types.
- Psalm resolves it to
static.
Literals
Section titled “Literals”Boolean, null, integer, float and string literals.
| PHPStan | Psalm | TypeLang | |
|---|---|---|---|
| supported | 29/30 | 11/30 | 30/30 |
true|false |
✓ | ✓ | ✓ |
42 |
✓ | ✓ | ✓ |
-42 |
✓ | ✓ | ✓ |
1.5 |
✓ | ✓ | ✓ |
-1.5 |
✓ | ✓ | ✓ |
'a' |
✓ | ✓ | ✓ |
"a" |
✓ | ✓ | ✓ |
1|2|3 |
✓ | ✓ | ✓ |
'a'|'b' |
✓ | ✓ | ✓ |
true |
✓ | ✓ | ✓ |
null |
✓ | ✓ | ✓ |
+1 |
✓ | ✗ 1 | ✓ |
- 1 |
✗ 2 | ! 3 | ✓ |
007 |
✓ | ✗ 4 | ✓ |
0x1F |
✓ | ✗ 5 | ✓ |
-0x1F |
✓ | ✗ 5 | ✓ |
0b101 |
✓ | ✗ 6 | ✓ |
0o17 |
✓ | ✗ 7 | ✓ |
1e3 |
✓ | ✗ 8 | ✓ |
1_000.5 |
✓ | ✗ 9 | ✓ |
.5 |
✓ | ✗ 10 | ✓ |
1. |
✓ | ✗ 10 | ✓ |
1.5e3 |
✓ | ✗ 8 | ✓ |
9223372036854775808 |
✓ | ! 11 | ✓ |
-9223372036854775809 |
✓ | ! 12 | ✓ |
'a"b' |
✓ | ✗ 13 | ✓ |
"a\"b" |
✓ | ! 14 | ✓ |
"a\nb" |
✓ | ! 15 | ✓ |
"a\x41" |
✓ | ! 15 | ✓ |
"a\u{1F600}" |
✓ | ! 15 | ✓ |
- Psalm has no explicit plus sign in numbers.
- PHPStan does not allow a space after the sign of a number.
- Psalm reads it as
-1. - Psalm has no legacy octal numbers.
- Psalm has no hexadecimal numbers.
- Psalm has no binary numbers.
- Psalm has no
0ooctal prefix. - Psalm has no exponent in floats.
- Psalm has no digit separators in numbers.
- Psalm requires digits on both sides of the decimal point.
- Psalm clamps it to the maximum.
- Psalm clamps it to the minimum.
- Psalm does not allow a double quote inside a single-quoted string.
- Psalm keeps the backslash in the value.
- Psalm does not decode it.
Constants and masks
Section titled “Constants and masks”Global constants, class constants and masks (* as a wildcard in a constant name).
| PHPStan | Psalm | TypeLang | |
|---|---|---|---|
| supported | 9/17 | 12/17 | 15/17 |
PHP_EOL |
✓ | ✓ | ✓ |
\PHP_EOL |
✓ | ✓ | ✓ |
Foo::BAR |
✓ | ✓ | ✓ |
Foo\Bar::BAZ |
✓ | ✓ | ✓ |
Foo::class |
✓ | ✓ | ✓ |
Foo::BAR|Foo::BAZ |
✓ | ✓ | ✓ |
Foo::* |
✓ | ✓ | ✓ |
PHP_* |
✗ 1 | ✓ | ✓ |
Some\Any\CONST_* |
✗ 2 | ✓ | ✓ |
FOO*BAR |
✗ 3 | ✓ | ✓ |
*_SOME |
✗ 2 | ✗ 4 | ✓ |
Some\Any\* |
✗ 2 | ✗ 4 | ✓ |
\* |
✗ 2 | ✗ 4 | ✓ |
Foo::*_BAZ |
✓ | ✗ 4 | ✓ |
Foo::B*R |
✓ | ✗ 4 | ✓ |
$this::BAR |
✗ 5 | ✓ | ✗ 6 |
$this::class |
✗ 5 | ✓ | ✗ 6 |
- PHPStan has masks only for class constants.
- PHPStan has masks only for class constants,
Foo::BAR_*, and none for global ones. - PHPStan allows a star only at the end of a constant name.
- Psalm allows a star only at the end of a constant name.
- PHPStan does not allow
$thisbefore::. - TypeLang does not allow
$thisbefore::.
Lists and offsets
Section titled “Lists and offsets”List T[] and offset access T[K].
| PHPStan | Psalm | TypeLang | |
|---|---|---|---|
| supported | 19/21 | 9/21 | 21/21 |
int[] |
✓ | ✓ | ✓ |
int[][] |
✓ | ✓ | ✓ |
(A|B)[] |
✓ | ✓ | ✓ |
array<int>[] |
✓ | ✓ | ✓ |
?int[] |
✓ | ✓ | ✓ |
int[]|null |
✓ | ✓ | ✓ |
Foo::BAR[] |
✓ | ✓ | ✓ |
T[K] |
✓ | ✓ | ✓ |
T[int] |
✓ | ✗ 1 | ✓ |
T['a'] |
✓ | ✗ 2 | ✓ |
T[Foo::A] |
✓ | ✗ 2 | ✓ |
T[K|L] |
✓ | ✗ 2 | ✓ |
T[?K] |
✓ | ✗ 2 | ✓ |
(A|B)[K] |
✓ | ✗ 2 | ✓ |
(?T)[K] |
✓ | ✗ 2 | ✓ |
Foo<int>[K] |
✓ | ✗ 2 | ✓ |
list<int>[0] |
✓ | ✗ 2 | ✓ |
array{a: int}['a'] |
✓ | ✗ 2 | ✓ |
T [K] |
✗ 3 | ✓ | ✓ |
int\n[] |
✗ 3 | ! 4 | ✓ |
$this[] |
✓ | ! 5 | ✓ |
- Psalm accepts only declared templates.
- Psalm supports offset access only on a template name,
T[K], and only with a template as the offset. - PHPStan does not allow a space before
[. - Psalm glues it into the name.
- Psalm resolves
$thistostatic.
Logical types
Section titled “Logical types”Union |, intersection & and nullable ?, and how they bind next to each other.
| PHPStan | Psalm | TypeLang | |
|---|---|---|---|
| supported | 12/22 | 14/22 | 22/22 |
A|B |
✓ | ✓ | ✓ |
A|B|C |
✓ | ✓ | ✓ |
A&B |
✓ | ✓ | ✓ |
A&B&C |
✓ | ✓ | ✓ |
(A|B)&C |
✓ | ✓ | ✓ |
(A&B)|C |
✓ | ✓ | ✓ |
?int |
✓ | ✓ | ✓ |
A&B|C |
✗ 1 | ✓ | ✓ |
A|B&C |
✗ 1 | ✓ | ✓ |
A&B|C&D |
✗ 1 | ✓ | ✓ |
?A|B |
✗ 2 | ✓ | ✓ |
?T|U[] |
✗ 3 | ✓ | ✓ |
A|?B |
✗ 4 | ✓ | ✓ |
?A&B |
✗ 5 | ! 6 | ✓ |
A&?B |
✗ 7 | ! 8 | ✓ |
?A&?B |
✗ 1 | ! 9 | ✓ |
(?A)&B |
✓ | ! 10 | ✓ |
(A&B)&C |
✓ | ! 9 | ✓ |
A[]|B[] |
✓ | ! 11 | ✓ |
A[]&B[] |
✓ | ! 11 | ✓ |
T|U[K] |
✓ | ✓ | ✓ |
(A|?B)[] |
✗ 1 | ! 9 | ✓ |
- PHPStan rejects it on purpose: it is stricter and requires parentheses, because the priority may be non-obvious.
- PHPStan rejects it on purpose: it is stricter and requires parentheses, because the priority may be non-obvious:
(?A)|Bor?(A|B). - PHPStan rejects it on purpose: it is stricter and requires parentheses, because the priority may be non-obvious:
(?T)|U[],?(T|U[])or?(T|U)[]. - PHPStan rejects it on purpose: it is stricter and requires parentheses, because the priority may be non-obvious:
A|(?B). - PHPStan rejects it on purpose: it is stricter and requires parentheses, because the priority may be non-obvious:
(?A)&Bor?(A&B). - Psalm reads
null|(A&B), the mark binds weaker there. - PHPStan rejects it on purpose: it is stricter and requires parentheses, because the priority may be non-obvious:
A&(?B). - Psalm silently drops the
null. - Psalm loses
B. - The only form PHPStan accepts. Psalm drops the
null. - Psalm merges the arrays into one.
Generics
Section titled “Generics”Arguments of Name<...>.
| PHPStan | Psalm | TypeLang | |
|---|---|---|---|
| supported | 12/14 | 8/14 | 14/14 |
Foo\Bar<int> |
✓ | ✓ | ✓ |
array<int, string> |
✓ | ✓ | ✓ |
Foo<int> |
✓ | ✓ | ✓ |
iterable<int> |
✓ | ✓ | ✓ |
list<int> |
✓ | ✓ | ✓ |
non-empty-list<int> |
✓ | ✓ | ✓ |
Foo<int, string,> |
✓ | ✗ 1 | ✓ |
Foo<*> |
✓ | ✗ 2 | ✓ |
Foo<int, *> |
✓ | ✗ 2 | ✓ |
Foo<covariant T> |
✓ | ! 3 | ✓ |
Foo<contravariant T> |
✓ | ! 3 | ✓ |
Foo<invariant T> |
✗ 4 | ✓ | ✓ |
Foo<int>[K] |
✓ | ✗ 5 | ✓ |
Foo<T is int ? A : B> |
✗ 6 | ✓ | ✓ |
- Psalm does not allow a trailing comma in generic arguments.
- Psalm has no wildcard
*as a generic argument. - Psalm drops the keyword silently.
- PHPStan knows only the
covariantandcontravariantkeywords. - Psalm supports offset access only on a template name,
T[K], and only with a template as the offset. - PHPStan requires parentheses around a conditional type, even as a generic argument.
Templates
Section titled “Templates”Template parameters of a callable: callable<T of X = Y>(T): T.
| PHPStan | Psalm | TypeLang | |
|---|---|---|---|
| supported | 11/12 | 0/12 | 12/12 |
callable<T>(T): T |
✓ | ✗ 1 | ✓ |
callable<T, U,>(T): U |
✓ | ✗ 1 | ✓ |
callable<T of int>(T): T |
✓ | ✗ 1 | ✓ |
callable<T as int>(T): T |
✓ | ✗ 1 | ✓ |
callable<T super int>(T): T |
✓ | ✗ 1 | ✓ |
callable<T of A super B>(): void |
✓ | ✗ 1 | ✓ |
callable<T = int>(T): T |
✓ | ✗ 1 | ✓ |
callable<T of int = int>(T): T |
✓ | ✗ 1 | ✓ |
callable<covariant T>(T): T |
✗ 2 | ✗ 1 | ✓ |
Closure<T>(T): T |
✓ | ✗ 1 | ✓ |
pure-Closure<T>(T): T |
✓ | ✗ 1 | ✓ |
Foo<T>(T): T |
✓ | ✗ 1 | ✓ |
- Psalm has no template parameters for callables.
- PHPStan has no variance on template parameters of a callable.
Callable
Section titled “Callable”Parameters, return types and modifiers of callable(...) and Closure(...).
| PHPStan | Psalm | TypeLang | |
|---|---|---|---|
| supported | 19/32 | 14/32 | 31/32 |
callable(): void |
✓ | ✓ | ✓ |
callable(int): void |
✓ | ✓ | ✓ |
callable(int $a): void |
✓ | ✓ | ✓ |
callable(int ...$a): void |
✓ | ✓ | ✓ |
Closure(int): void |
✓ | ✓ | ✓ |
pure-callable(int): void |
✓ | ✓ | ✓ |
callable(int) |
✗ 1 | ✓ | ✓ |
callable(...int): void |
✗ 2 | ✓ | ✓ |
callable(int...): void |
✓ | ✓ | ✓ |
callable(int... $a): void |
✓ | ✗ 3 | ✓ |
callable(...): void |
✗ 4 | ✓ | ✗ 5 |
callable(...$a): void |
✗ 4 | ✗ 6 | ✓ |
callable($a): void |
✗ 4 | ✗ 6 | ✓ |
callable(int &$a): void |
✓ | ✗ 7 | ✓ |
callable(&$a): void |
✗ 4 | ✗ 6 | ✓ |
callable(int&): void |
✓ | ! 8 | ✓ |
callable(int &...$a): void |
✓ | ! 8 | ✓ |
callable(int $a=): void |
✓ | ✗ 9 | ✓ |
callable(int=): void |
✓ | ✓ | ✓ |
callable(int = 42): void |
✗ 10 | ! 11 | ✓ |
callable(int $a = 42): void |
✗ 12 | ✗ 13 | ✓ |
callable(int $a = -1): void |
✗ 10 | ✗ 13 | ✓ |
callable(int $a = PHP_INT_MAX): void |
✗ 10 | ✗ 13 | ✓ |
callable(int $a = Foo::BAR): void |
✗ 10 | ✗ 13 | ✓ |
callable(): $this |
✓ | ! 14 | ✓ |
callable(): T is int ? A : B |
✗ 15 | ✓ | ✓ |
foo(T): void |
✓ | ✗ 16 | ✓ |
callable (int): void |
✓ | ✓ | ✓ |
callable(): T|U |
✓ | ✓ | ✓ |
callable(): T&U |
✓ | ! 17 | ✓ |
callable(): ?T|U |
✓ | ! 17 | ✓ |
callable(): callable(): T|U |
✗ 18 | ! 18 | ✓ |
- PHPStan rejects it on purpose: it requires a return type for strict signatures, and it avoids the conflict with a variance in front of a group,
Generic<covariant(T)>againstGeneric<covariant(T): void>. - PHPStan supports only the postfix form,
callable(int...): void. - Psalm does not allow a name after
.... - PHPStan rejects it on purpose: it requires a type on every parameter.
- TypeLang requires a type or a name after
.... - Psalm requires a type for every parameter.
- Psalm has no by-reference marker
&with a parameter name. - Psalm drops the
&. - Psalm has no optional marker
=after a parameter name. - PHPStan has the optional marker
=, but no default value after it. - Psalm skips it and loses the value.
- PHPStan has no default values of parameters, only the bare
=. - Psalm has no default values of parameters.
- Psalm resolves it to
static. - PHPStan requires parentheses around a conditional return type.
- Psalm reads only
callableandClosurebefore the parentheses of a callable. - Psalm folds it into the return type.
- PHPStan rejects it, Psalm folds the union.
Shapes
Section titled “Shapes”Fields of array{}, list{} and object{}.
| PHPStan | Psalm | TypeLang | |
|---|---|---|---|
| supported | 23/28 | 13/28 | 28/28 |
array{} |
✓ | ✓ | ✓ |
array{a: int} |
✓ | ✓ | ✓ |
array{a?: int} |
✓ | ✓ | ✓ |
array{int, string} |
✓ | ✓ | ✓ |
array{0: int} |
✓ | ✓ | ✓ |
array{'a': int} |
✓ | ✓ | ✓ |
array{a: array{b: int}} |
✓ | ✓ | ✓ |
array{a: int, ...} |
✓ | ✓ | ✓ |
list{int, string} |
✓ | ✓ | ✓ |
object{a: int} |
✓ | ✓ | ✓ |
array{int, string,} |
✓ | ✗ 1 | ✓ |
array{a: int, string} |
✓ | ✗ 2 | ✓ |
array{Foo::BAR: int} |
✓ | ✗ 3 | ✓ |
array{covariant: int} |
✓ | ✗ 4 | ✓ |
array{'Foo\Bar': int} |
✓ | ! 5 | ✓ |
array{- 1: int} |
✗ 6 | ✓ | ✓ |
array{...} |
✓ | ! 7 | ✓ |
array{a: int, ...<string>} |
✓ | ✗ 8 | ✓ |
array{a: int, ...<string, int>} |
✓ | ✓ | ✓ |
list{1: int} |
✓ | ✗ 9 | ✓ |
list{...} |
✓ | ! 10 | ✓ |
non-empty-array{a: int} |
✓ | ✗ 11 | ✓ |
object{a: int,} |
✓ | ✗ 1 | ✓ |
object{a: int, ...} |
✗ 12 | ! 13 | ✓ |
object{0: int} |
✗ 14 | ✓ | ✓ |
object{Foo::BAR: int} |
✗ 14 | ✗ 3 | ✓ |
Foo{a: int} |
✗ 15 | ✗ 16 | ✓ |
array{a: int} | array{b: string} |
✓ | ! 17 | ✓ |
- Psalm does not allow a trailing comma in a shape.
- Psalm does not allow named and positional fields in one shape.
- Psalm does not allow a class constant as a key.
- Psalm does not accept a reserved word as a key.
- Psalm drops the backslash from a string key.
- PHPStan does not allow a space after the sign of a key.
- Psalm reads an empty array.
- Psalm does not read a single type argument in the unsealed marker.
- Psalm does not allow explicit keys in a list shape.
- Psalm loses the tail.
- Psalm has no shape for
non-empty-array. - PHPStan has no unsealed object shape.
- Psalm drops
.... - PHPStan allows only names as the keys of an object shape.
- PHPStan allows a shape only after
array,listandobject. - Psalm allows a shape only after
array,listandobject. - Psalm merges them into one.
Conditional types
Section titled “Conditional types”The T is U ? A : B family.
| PHPStan | Psalm | TypeLang | |
|---|---|---|---|
| supported | 11/18 | 5/18 | 18/18 |
(T is int ? A : B) |
✓ | ✓ | ✓ |
(T is not int ? A : B) |
✓ | ✓ | ✓ |
($a is int ? A : B) |
✓ | ✓ | ✓ |
T is int ? A : B |
✗ 1 | ✗ 2 | ✓ |
T is not int ? A : B |
✗ 1 | ✗ 2 | ✓ |
$a is int ? A : B |
✗ 1 | ✗ 2 | ✓ |
(T is ?int ? A : B) |
✓ | ✗ 3 | ✓ |
(T is int[] ? A : B) |
✓ | ✗ 4 | ✓ |
(T is callable(int): void ? A : B) |
✓ | ✗ 5 | ✓ |
(T is int ? A : B is C ? D : E) |
✓ | ✗ 6 | ✓ |
(T is int ? A : (B is C ? D : E)) |
✓ | ✗ 7 | ✓ |
(T is $this ? A : B) |
✓ | ! 8 | ✓ |
($this is int ? A : B) |
✓ | ✗ 9 | ✓ |
callable(int &$a): ($a is int ? A : B) |
✓ | ✗ 10 | ✓ |
array{a: T is int ? A : B} |
✗ 11 | ✓ | ✓ |
callable(T $a): T is int ? A : B |
✗ 12 | ✓ | ✓ |
?T is U ? V : Z |
✗ 13 | ! 14 | ✓ |
A|B is C ? D : E |
✗ 15 | ✗ 15 | ✓ |
- PHPStan requires parentheses around a conditional type.
- Psalm requires parentheses around a conditional type.
- Psalm does not allow a nullable type as the target of a condition.
- Psalm does not allow a list type as the target of a condition.
- Psalm does not allow a callable as the target of a condition.
- Psalm does not allow a conditional type in the else branch without parentheses.
- Psalm does not allow a nested condition in the else branch, even in parentheses.
- Psalm resolves
$thistostatic. - Psalm does not allow
$thisas the subject of a condition. - Psalm has no by-reference marker
&with a parameter name. - PHPStan requires parentheses around a conditional type inside a shape.
- PHPStan requires parentheses around a conditional return type.
- PHPStan does not allow
?in front of the subject of a condition. - Psalm reads it as
(T is U:fn-corpus as mixed ? V:fn-corpus as mixed : Z)|null. - TypeLang binds the condition weaker than the union, the others reject it.
Special names
Section titled “Special names”Names that carry meaning in PHPStan and Psalm. PHPStan and TypeLang read them as ordinary Name<arguments> and leave the meaning to the next layer, Psalm checks them while parsing.
| PHPStan | Psalm | TypeLang | |
|---|---|---|---|
| supported | 16/16 | 6/16 | 16/16 |
int<0, max> |
✓ | ✓ | ✓ |
int<min, 0> |
✓ | ✓ | ✓ |
class-string<Foo> |
✓ | ✓ | ✓ |
key-of<T> |
✓ | ✓ | ✓ |
value-of<T> |
✓ | ✓ | ✓ |
int-mask<1, 2, 4> |
✓ | ✓ | ✓ |
int<10, 0> |
✓ | ✗ 1 | ✓ |
int<PHP_INT_MIN, PHP_INT_MAX> |
✓ | ✗ 2 | ✓ |
int-mask<1, 2, 4,> |
✓ | ✗ 3 | ✓ |
int-mask-of<1|2|4> |
✓ | ✗ 4 | ✓ |
class-string<int> |
✓ | ✗ 5 | ✓ |
enum-string<Foo> |
✓ | ! 6 | ✓ |
trait-string<Foo> |
✓ | ✗ 7 | ✓ |
key-of<T, U> |
✓ | ! 8 | ✓ |
uppercase-string |
✓ | ! 9 | ✓ |
open-resource |
✓ | ✗ 10 | ✓ |
- Psalm checks an integer range while parsing: the minimum must not exceed the maximum.
- Psalm accepts only
min,maxand integer literals as the bounds of a range. - Psalm does not allow a trailing comma in
int-mask. - Psalm requires a class constant mask as the argument of
int-mask-of. - Psalm checks while parsing that the argument of
class-stringis a class. - Psalm turns it into
class-string. - Psalm has no
trait-string. - Psalm drops the second argument.
- Psalm drops the refinement.
- Psalm has no
open-resource.
Whitespace and comments
Section titled “Whitespace and comments”What may stand between tokens. Newlines are written as \n.
| PHPStan | Psalm | TypeLang | |
|---|---|---|---|
| supported | 11/21 | 11/21 | 21/21 |
\nint |
✗ 1 | ✗ 2 | ✓ |
int |\n string |
✗ 3 | ✗ 4 | ✓ |
array<\n int,\n string\n> |
✓ | ✗ 5 | ✓ |
callable(int\n$a): void |
✗ 6 | ✗ 7 | ✓ |
array {a: int} |
✗ 8 | ✓ | ✓ |
int [] |
✓ | ✓ | ✓ |
int [ ] |
✓ | ✓ | ✓ |
T [K] |
✗ 9 | ✓ | ✓ |
Foo <int> |
✓ | ✓ | ✓ |
array <K, V> |
✓ | ✓ | ✓ |
Foo :: BAR |
✓ | ✓ | ✓ |
? int |
✓ | ✓ | ✓ |
int | string |
✓ | ✓ | ✓ |
callable( int ): void |
✓ | ✓ | ✓ |
callable(int , string): void |
✓ | ✓ | ✓ |
callable<T> (T): void |
✓ | ✗ 10 | ✓ |
int /* c */ |
✗ 11 | ✗ 12 | ✓ |
int // c |
✗ 11 | ✗ 12 | ✓ |
int # c |
✗ 11 | ✗ 12 | ✓ |
array{a: int /* c */, b: string} |
✗ 11 | ✗ 12 | ✓ |
Some</* a */int/* b */,/* c */string> |
✗ 11 | ✗ 12 | ✓ |
- PHPStan does not allow a line break at the very start.
- Psalm does not allow a line break at the very start.
- PHPStan does not allow a line break after an operator.
- Psalm does not allow a line break after an operator.
- Psalm does not allow line breaks inside generic arguments.
- PHPStan does not allow a line break between a type and a parameter name.
- Psalm does not allow a line break between a type and a parameter name.
- PHPStan does not allow a space before
{of a shape. - PHPStan does not allow a space before
[. - Psalm has no template parameters for callables.
- PHPStan does not allow comments in a type.
- Psalm does not allow comments in a type.
Malformed input
Section titled “Malformed input”Inputs that must be rejected. A parser that accepts them reads garbage as a type.
| PHPStan | Psalm | TypeLang | |
|---|---|---|---|
| supported | 29/34 | 5/34 | 33/34 |
int string |
✓ | ! 1 | ✓ |
Foo<A B> |
✓ | ! 2 | ✓ |
array{a: int b: string} |
✓ | ! 3 | ✓ |
int) |
✓ | ! 4 | ✓ |
int| |
✓ | ! 5 | ✓ |
A& |
✓ | ! 5 | ✓ |
A&&B |
✓ | ! 6 | ✓ |
(A|) |
✓ | ! 5 | ✓ |
??int |
✓ | ! 7 | ✓ |
int?[] |
✓ | ! 8 | ✓ |
int ? a |
✓ | ! 9 | ✓ |
int * |
✓ | ! 10 | ✓ |
PHP_ * |
✓ | ! 11 | ✓ |
in t |
✓ | ! 12 | ✓ |
'a |
✓ | ! 13 | ✓ |
'a''b' |
✓ | ! 14 | ✓ |
Foo\ |
✓ | ! 15 | ✓ |
Foo\\Bar |
✓ | ! 16 | ✓ |
foo- |
! 17 | ✓ | ✓ |
08 |
! 18 | ✓ | ✓ |
1__000 |
✓ | ! 19 | ✓ |
1._5 |
! 20 | ✓ | ✓ |
Foo::BAR::class |
✓ | ! 21 | ✓ |
(Foo)::class |
✓ | ! 22 | ✓ |
Foo::BAR-BAZ |
! 23 | ✓ | ✓ |
Foo<T of Bar> |
✓ | ! 24 | ✓ |
Foo<out T> |
✓ | ! 25 | ✓ |
array{a: int, ...int} |
✓ | ! 4 | ✓ |
array{$a: int} |
✓ | ! 26 | ✓ |
array{PHP_*: int} |
✓ | ! 26 | ✓ |
array{a: int, a: string} |
! 27 | ✓ | ! 27 |
(T is not not int ? A : B) |
✓ | ! 3 | ✓ |
T is int ? A |
✓ | ! 28 | ✓ |
A is B ? C |
✓ | ! 29 | ✓ |
- Psalm glues them into
intstring. - Psalm glues them.
- Psalm glues the words.
- Psalm ignores it.
- Psalm ignores a dangling operator and reads the rest.
- Psalm reads
A&B. - Psalm folds it.
- Psalm drops the mark and the brackets.
- Psalm ignores the tail.
- Psalm accepts a trailing
*. - Psalm glues it into
PHP_*. - Psalm reads
int. - Psalm accepts and truncates it.
- Psalm keeps the first.
- Psalm accepts and ignores it.
- Psalm accepts a doubled backslash as part of a name.
- PHPStan accepts a trailing hyphen in a name.
- PHPStan accepts a digit outside of the octal range after a leading zero.
- Psalm accepts a doubled digit separator.
- PHPStan accepts a separator right after the decimal point.
- Psalm drops the second constant.
- Psalm drops the constant.
- PHPStan accepts a hyphen in a constant name.
- Psalm reads a template map.
- Psalm glues the words into
outT. - Psalm reads a string key.
- Psalm rejects it, PHPStan and TypeLang keep both.
- Psalm drops the condition.
- Psalm reads
A.