1 | <?php |
||
10 | class ChipPot |
||
11 | { |
||
12 | /** |
||
13 | * @var ChipStackCollection |
||
14 | */ |
||
15 | private $chips; |
||
16 | |||
17 | /** |
||
18 | * @var PlayerCollection |
||
19 | */ |
||
20 | private $players; |
||
21 | |||
22 | 52 | private function __construct() |
|
27 | |||
28 | /** |
||
29 | * @return ChipPot |
||
30 | */ |
||
31 | 52 | public static function create(): ChipPot |
|
35 | |||
36 | /** |
||
37 | * @param Chips $chips |
||
38 | * @param Player $player |
||
39 | * |
||
40 | * @return ChipPot |
||
41 | */ |
||
42 | 21 | public function addChips(Chips $chips, Player $player): ChipPot |
|
54 | |||
55 | /** |
||
56 | * @return ChipStackCollection |
||
57 | */ |
||
58 | 21 | public function chips(): ChipStackCollection |
|
62 | |||
63 | /** |
||
64 | * @return PlayerCollection |
||
65 | */ |
||
66 | 21 | public function players(): PlayerCollection |
|
70 | |||
71 | /** |
||
72 | * @return Chips |
||
73 | */ |
||
74 | 13 | public function total(): Chips |
|
78 | |||
79 | /** |
||
80 | * @return int |
||
81 | */ |
||
82 | 3 | public function totalAmount(): int |
|
86 | |||
87 | /** |
||
88 | * @param ChipPot $object |
||
89 | * |
||
90 | * @return bool |
||
91 | */ |
||
92 | 11 | public function equals(ChipPot $object): bool |
|
99 | |||
100 | /** |
||
101 | * @return string |
||
102 | */ |
||
103 | 1 | public function __toString() |
|
113 | } |
||
114 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: