2020-03-19 12:32:49 -04:00
|
|
|
|
# DuplicateClass
|
|
|
|
|
|
|
|
|
|
Emitted when a class is defined twice
|
|
|
|
|
|
|
|
|
|
```php
|
2020-03-20 19:13:46 -04:00
|
|
|
|
<?php
|
|
|
|
|
|
2020-03-19 12:32:49 -04:00
|
|
|
|
class A {}
|
|
|
|
|
class A {}
|
|
|
|
|
```
|
2020-03-21 10:13:11 -04:00
|
|
|
|
|
|
|
|
|
## Why this is bad
|
|
|
|
|
|
|
|
|
|
The above code won’t compile.
|
|
|
|
|
|
|
|
|
|
PHP does allow you to define a class conditionally:
|
|
|
|
|
|
|
|
|
|
```php
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
if (rand(0, 1)) {
|
|
|
|
|
class A {
|
|
|
|
|
public function __construct(string $s) {}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
class A {
|
|
|
|
|
public function __construct(object $o) {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
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.
|