1 | <?php |
||
14 | class World |
||
15 | { |
||
16 | use ImmutableTrait, SerializableTrait; |
||
17 | |||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | private $name; |
||
22 | |||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | private $online; |
||
27 | |||
28 | /** |
||
29 | * @var |
||
30 | */ |
||
31 | private $onlineRecord; |
||
32 | |||
33 | /** |
||
34 | * @var |
||
35 | */ |
||
36 | private $creationDate; |
||
37 | |||
38 | /** |
||
39 | * @var |
||
40 | */ |
||
41 | private $location; |
||
42 | |||
43 | /** |
||
44 | * @var |
||
45 | */ |
||
46 | private $pvpType; |
||
47 | |||
48 | /** |
||
49 | * @var |
||
50 | */ |
||
51 | private $worldQuestTitles; |
||
52 | |||
53 | /** |
||
54 | * @var |
||
55 | */ |
||
56 | private $battleyeStatus; |
||
57 | |||
58 | /** |
||
59 | * @var |
||
60 | */ |
||
61 | private $playersOnline; |
||
62 | |||
63 | /** |
||
64 | * World constructor. |
||
65 | * @param string $name |
||
66 | * @param int $online |
||
67 | * @throws ImmutableException |
||
68 | */ |
||
69 | public function __construct(string $name, int $online) |
||
76 | |||
77 | /** |
||
78 | * @param array $array |
||
79 | * @return World |
||
80 | * @throws ImmutableException |
||
81 | */ |
||
82 | public static function createFromArray(array $array) |
||
96 | |||
97 | /** |
||
98 | * @return string |
||
99 | */ |
||
100 | public function getName(): string |
||
104 | |||
105 | /** |
||
106 | * @return int |
||
107 | */ |
||
108 | public function getOnline(): int |
||
112 | |||
113 | /** |
||
114 | * @return OnlineRecord |
||
115 | */ |
||
116 | public function getOnlineRecord(): OnlineRecord |
||
120 | |||
121 | /** |
||
122 | * @return string |
||
123 | */ |
||
124 | public function getCreationDate(): string |
||
128 | |||
129 | /** |
||
130 | * @return string |
||
131 | */ |
||
132 | public function getLocation(): string |
||
136 | |||
137 | /** |
||
138 | * @return string |
||
139 | */ |
||
140 | public function getPvpType(): string |
||
144 | |||
145 | /** |
||
146 | * @return array |
||
147 | */ |
||
148 | public function getWorldQuestTitles(): Collection |
||
152 | |||
153 | /** |
||
154 | * @return string |
||
155 | */ |
||
156 | public function getBattleyeStatus(): string |
||
160 | |||
161 | /** |
||
162 | * @return Character[] |
||
163 | */ |
||
164 | public function getPlayersOnline(): Collection |
||
168 | |||
169 | /** |
||
170 | * Gets Carbon from battleye status string. |
||
171 | * |
||
172 | * @return Carbon|null |
||
173 | * @throws Exception |
||
174 | */ |
||
175 | public function getBattlEyedAt(): ?Carbon |
||
188 | } |
||
189 |
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: