File tree 3 files changed +33
-7
lines changed
docs/running_psalm/issues
3 files changed +33
-7
lines changed Original file line number Diff line number Diff line change @@ -6,10 +6,10 @@ Emitted when an array has a key more than once
6
6
<?php
7
7
8
8
$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' ,
13
13
];
14
14
```
15
15
@@ -21,9 +21,9 @@ Remove the offending duplicates:
21
21
<?php
22
22
23
23
$arr = [
24
- 'a' => 1 ,
25
- 'b' => 2 ,
26
- 'c' => 4 ,
24
+ 'a' => 'one' ,
25
+ 'b' => 'two' ,
26
+ 'c' => 'three' ,
27
27
];
28
28
```
29
29
Original file line number Diff line number Diff line change @@ -8,3 +8,25 @@ Emitted when a class is defined twice
8
8
class A {}
9
9
class A {}
10
10
```
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.
Original file line number Diff line number Diff line change @@ -7,3 +7,7 @@ Emitted when a function has a param defined twice
7
7
8
8
function foo(int $b, string $b) {}
9
9
```
10
+
11
+ ## Why this is bad
12
+
13
+ The above code produces a fatal error in PHP.
You can’t perform that action at this time.
0 commit comments