1 | <?php |
||
23 | class Reflection implements ReflectionInterface |
||
24 | { |
||
25 | use Serializable; |
||
26 | |||
27 | /** |
||
28 | * @var array|TypeDefinition[] |
||
29 | */ |
||
30 | protected $types = []; |
||
31 | |||
32 | /** |
||
33 | * @var array|DocumentInterface[] |
||
34 | */ |
||
35 | protected $documents = []; |
||
36 | |||
37 | /** |
||
38 | * @return iterable |
||
39 | */ |
||
40 | 4 | public function getDocuments(): iterable |
|
44 | |||
45 | /** |
||
46 | * @param DocumentInterface $document |
||
47 | */ |
||
48 | 4 | public function addDocument(DocumentInterface $document): void |
|
52 | |||
53 | /** |
||
54 | * @param Type|null $of |
||
55 | * @return iterable|TypeDefinition[] |
||
56 | */ |
||
57 | 3 | public function all(Type $of = null): iterable |
|
65 | |||
66 | /** |
||
67 | * @param string $name |
||
68 | * @param TypeDefinition|null $from |
||
69 | * @return TypeDefinition |
||
70 | * @throws TypeNotFoundException |
||
71 | */ |
||
72 | 1 | public function get(string $name, TypeDefinition $from = null): TypeDefinition |
|
80 | |||
81 | /** |
||
82 | * @param string $name |
||
83 | * @return null|TypeDefinition |
||
84 | */ |
||
85 | 4 | public function find(string $name): ?TypeDefinition |
|
89 | |||
90 | /** |
||
91 | * @param string $name |
||
92 | * @param TypeDefinition $from |
||
93 | * @return TypeNotFoundException |
||
94 | */ |
||
95 | protected function typeNotFound(string $name, TypeDefinition $from = null): TypeNotFoundException |
||
107 | |||
108 | /** |
||
109 | * @param TypeDefinition $type |
||
110 | * @return ReflectionInterface |
||
111 | */ |
||
112 | 2 | public function add(TypeDefinition $type): ReflectionInterface |
|
119 | |||
120 | /** |
||
121 | * @param string $name |
||
122 | * @return bool |
||
123 | */ |
||
124 | 3 | public function has(string $name): bool |
|
128 | } |
||
129 |
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: