Skip to content

Commit e49a5dd

Browse files
committed
Add more docs
1 parent 3f26152 commit e49a5dd

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

docs/running_psalm/issues/DuplicateArrayKey.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Emitted when an array has a key more than once
66
<?php
77

88
$arr = [
9-
'a' => 1,
10-
'b' => 2,
11-
'c' => 3,
12-
'c' => 4,
9+
'a' => 'one',
10+
'b' => 'two',
11+
'c' => 'this text will be overwritten by the next line',
12+
'c' => 'three',
1313
];
1414
```
1515

@@ -21,9 +21,9 @@ Remove the offending duplicates:
2121
<?php
2222

2323
$arr = [
24-
'a' => 1,
25-
'b' => 2,
26-
'c' => 4,
24+
'a' => 'one',
25+
'b' => 'two',
26+
'c' => 'three',
2727
];
2828
```
2929

docs/running_psalm/issues/DuplicateClass.md

+22
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,25 @@ Emitted when a class is defined twice
88
class A {}
99
class A {}
1010
```
11+
12+
## Why this is bad
13+
14+
The above code won’t compile.
15+
16+
PHP does allow you to define a class conditionally:
17+
18+
```php
19+
<?php
20+
21+
if (rand(0, 1)) {
22+
class A {
23+
public function __construct(string $s) {}
24+
}
25+
} else {
26+
class A {
27+
public function __construct(object $o) {}
28+
}
29+
}
30+
```
31+
32+
But Psalm _really_ doesn't want you to use this pattern – it's impossible for Psalm to know (without using reflection) which class is getting used.

docs/running_psalm/issues/DuplicateParam.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ Emitted when a function has a param defined twice
77

88
function foo(int $b, string $b) {}
99
```
10+
11+
## Why this is bad
12+
13+
The above code produces a fatal error in PHP.

0 commit comments

Comments
 (0)