1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | namespace src; |
||
4 | use src\{Nombres,PrimerApellido,SegundoApellido}; |
||
0 ignored issues
–
show
This use statement conflicts with another class in this namespace,
src\SegundoApellido . Consider defining an alias.
Let?s assume that you have a directory layout like this: .
|-- OtherDir
| |-- Bar.php
| `-- Foo.php
`-- SomeDir
`-- Foo.php
and let?s assume the following content of // Bar.php
namespace OtherDir;
use SomeDir\Foo; // This now conflicts the class OtherDir\Foo
If both files PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as // Bar.php
namespace OtherDir;
use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
![]() This use statement conflicts with another class in this namespace,
src\Nombres . Consider defining an alias.
Let?s assume that you have a directory layout like this: .
|-- OtherDir
| |-- Bar.php
| `-- Foo.php
`-- SomeDir
`-- Foo.php
and let?s assume the following content of // Bar.php
namespace OtherDir;
use SomeDir\Foo; // This now conflicts the class OtherDir\Foo
If both files PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as // Bar.php
namespace OtherDir;
use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
![]() |
|||
5 | |||
6 | class NombreCompleto |
||
7 | { |
||
8 | private $_nombres; |
||
9 | private $_primerApellido; |
||
10 | private $_segundoApellido; |
||
11 | |||
12 | public function __construct |
||
13 | ( |
||
14 | Nombres $Nombres, |
||
15 | PrimerApellido $PrimerApellido, |
||
16 | SegundoApellido $SegundoApellido |
||
17 | ) |
||
18 | { |
||
19 | $this->_nombres = $Nombres; |
||
20 | $this->_primerApellido = $PrimerApellido; |
||
21 | $this->_segundoApellido = $SegundoApellido; |
||
22 | } |
||
23 | |||
24 | public function nombreCompleto(): string |
||
25 | { |
||
26 | $espacio = ''; |
||
27 | |||
28 | if(strlen($this->segundoApellido()) > 0) |
||
29 | { |
||
30 | $espacio = ' '; |
||
31 | } |
||
32 | |||
33 | return $this->nombres().' '.$this->primerApellido().$espacio.$this->segundoApellido(); |
||
34 | } |
||
35 | |||
36 | public function nombres() |
||
37 | { |
||
38 | return $this->_nombres->nombres(); |
||
39 | } |
||
40 | |||
41 | public function primerApellido() |
||
42 | { |
||
43 | return $this->_primerApellido->primerApellido(); |
||
44 | } |
||
45 | |||
46 | public function segundoApellido() |
||
47 | { |
||
48 | return $this->_segundoApellido->segundoApellido(); |
||
49 | } |
||
50 | } |
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: