1 | <?php |
||
21 | class Config implements ArrayAccess, Iterator, Countable |
||
22 | { |
||
23 | /** |
||
24 | * Store |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $_store = []; |
||
29 | |||
30 | |||
31 | /** |
||
32 | * Position |
||
33 | * |
||
34 | * @var int |
||
35 | */ |
||
36 | protected $position = 0; |
||
37 | |||
38 | |||
39 | /** |
||
40 | * Load config |
||
41 | * |
||
42 | * @param string $config |
||
43 | * @return void |
||
44 | */ |
||
45 | public function __construct(?ConfigInterface $config=null) |
||
51 | |||
52 | |||
53 | /** |
||
54 | * Inject config adapter |
||
55 | * |
||
56 | * @param ConfigInterface $config |
||
57 | * @return Config |
||
58 | */ |
||
59 | public function inject(ConfigInterface $config): Config |
||
63 | |||
64 | |||
65 | /** |
||
66 | * Merge |
||
67 | * |
||
68 | * @return Config |
||
69 | */ |
||
70 | public function merge(Config $from): Config |
||
82 | |||
83 | |||
84 | /** |
||
85 | * Count |
||
86 | * |
||
87 | * @return int |
||
88 | */ |
||
89 | public function count() |
||
93 | |||
94 | /** |
||
95 | * Count |
||
96 | * |
||
97 | * @return int |
||
98 | */ |
||
99 | public function children() |
||
103 | |||
104 | |||
105 | /** |
||
106 | * Get entry |
||
107 | * |
||
108 | * @param string $key |
||
109 | * @return mixed |
||
110 | */ |
||
111 | public function __get($key) |
||
119 | |||
120 | |||
121 | /** |
||
122 | * Set offset |
||
123 | * |
||
124 | * @param int $offset |
||
125 | * @param mixed $value |
||
126 | * @return void |
||
127 | */ |
||
128 | public function offsetSet($offset, $value) |
||
136 | |||
137 | |||
138 | /** |
||
139 | * Count |
||
140 | * |
||
141 | * @param int $offset |
||
142 | * @return bool |
||
143 | */ |
||
144 | public function offsetExists($offset) |
||
148 | |||
149 | |||
150 | /** |
||
151 | * Unset offset |
||
152 | * |
||
153 | * @param int $offset |
||
154 | * @return void |
||
155 | */ |
||
156 | public function offsetUnset($offset) |
||
160 | |||
161 | |||
162 | /** |
||
163 | * Get value from offset |
||
164 | * |
||
165 | * @param int $offset |
||
166 | * @return mixed |
||
167 | */ |
||
168 | public function offsetGet($offset) |
||
172 | |||
173 | /** |
||
174 | * Rewind |
||
175 | * |
||
176 | * @return void |
||
177 | */ |
||
178 | public function rewind() |
||
182 | |||
183 | |||
184 | /** |
||
185 | * Get current |
||
186 | * |
||
187 | * @return mixed |
||
188 | */ |
||
189 | public function current() |
||
193 | |||
194 | |||
195 | /** |
||
196 | * Get key |
||
197 | * |
||
198 | * @return int |
||
199 | */ |
||
200 | public function key() |
||
204 | |||
205 | |||
206 | /** |
||
207 | * Next |
||
208 | * |
||
209 | * @return void |
||
210 | */ |
||
211 | public function next() |
||
215 | |||
216 | |||
217 | /** |
||
218 | * Valid |
||
219 | * |
||
220 | * @return bool |
||
221 | */ |
||
222 | public function valid() |
||
226 | } |
||
227 |
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: