Skip to content

Latest commit

 

History

History
32 lines (23 loc) · 542 Bytes

DuplicateClass.md

File metadata and controls

32 lines (23 loc) · 542 Bytes

DuplicateClass

Emitted when a class is defined twice

<?php

class A {}
class A {}

Why this is bad

The above code won’t compile.

PHP does allow you to define a class conditionally:

<?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.