| 1 | <?php |
||
| 13 | class PhpView implements ViewInterface { |
||
| 14 | use HasContextTrait; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * View name. |
||
| 18 | * |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | protected $name = ''; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Filepath to view. |
||
| 25 | * |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | protected $filepath = ''; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * {@inheritDoc} |
||
| 32 | */ |
||
| 33 | 1 | public function getName() { |
|
| 36 | |||
| 37 | /** |
||
| 38 | * {@inheritDoc} |
||
| 39 | */ |
||
| 40 | 1 | public function setName( $name ) { |
|
| 44 | |||
| 45 | /** |
||
| 46 | * Get filepath. |
||
| 47 | * |
||
| 48 | * @return string |
||
| 49 | */ |
||
| 50 | public function getFilepath() { |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Set filepath. |
||
| 56 | * |
||
| 57 | * @param string $filepath |
||
| 58 | * @return self $this |
||
| 59 | */ |
||
| 60 | public function setFilepath( $filepath ) { |
||
| 64 | |||
| 65 | /** |
||
| 66 | * {@inheritDoc} |
||
| 67 | */ |
||
| 68 | 7 | public function toString() { |
|
| 93 | |||
| 94 | /** |
||
| 95 | * {@inheritDoc} |
||
| 96 | */ |
||
| 97 | public function toResponse() { |
||
| 102 | } |
||
| 103 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes 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: