1 | <?php namespace BuildR\Foundation\Exception; |
||
28 | class AggregateException extends Exception implements \IteratorAggregate, Countable, ArrayConvertibleInterface { |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | private $collection = []; |
||
34 | |||
35 | /** |
||
36 | * Add a new exception to the stack |
||
37 | * |
||
38 | * @param \Exception|\Throwable $exception |
||
39 | */ |
||
40 | public function add($exception) { |
||
50 | |||
51 | /** |
||
52 | * Check the exception |
||
53 | * |
||
54 | * @param \Throwable|\Exception $exception |
||
55 | * @return bool |
||
56 | * |
||
57 | * @codeCoverageIgnore |
||
58 | */ |
||
59 | private function checkException($exception) { |
||
66 | |||
67 | /** |
||
68 | * Determines, the current exception stack contains any exception |
||
69 | * |
||
70 | * @return bool |
||
71 | */ |
||
72 | public function hasAny() { |
||
75 | |||
76 | /** |
||
77 | * {@inheritDoc} |
||
78 | */ |
||
79 | public function getIterator() { |
||
82 | |||
83 | /** |
||
84 | * {@inheritDoc} |
||
85 | */ |
||
86 | public function toArray() { |
||
89 | |||
90 | /** |
||
91 | * {@inheritDoc} |
||
92 | */ |
||
93 | public function count() { |
||
96 | |||
97 | } |
||
98 |
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: