chamilo /
chamilo-lms
| 1 | <?php |
||
| 2 | |||
| 3 | /* For licensing terms, see /license.txt */ |
||
| 4 | |||
| 5 | use Chamilo\PluginBundle\ExerciseFocused\Controller\DetailController; |
||
| 6 | use Chamilo\PluginBundle\ExerciseFocused\Entity\Log; |
||
| 7 | use Symfony\Component\HttpFoundation\Request as HttpRequest; |
||
|
0 ignored issues
–
show
|
|||
| 8 | use Symfony\Component\HttpFoundation\Response as HttpResponse; |
||
|
0 ignored issues
–
show
This use statement conflicts with another class in this namespace,
HttpResponse. 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.
Loading history...
|
|||
| 9 | |||
| 10 | require_once __DIR__.'/../../../main/inc/global.inc.php'; |
||
| 11 | |||
| 12 | if (!api_is_allowed_to_edit()) { |
||
| 13 | api_not_allowed(true); |
||
| 14 | } |
||
| 15 | |||
| 16 | $em = Database::getManager(); |
||
| 17 | $logRepository = $em->getRepository(Log::class); |
||
| 18 | |||
| 19 | $detailController = new DetailController( |
||
| 20 | ExerciseFocusedPlugin::create(), |
||
| 21 | HttpRequest::createFromGlobals(), |
||
| 22 | $em, |
||
| 23 | $logRepository |
||
| 24 | ); |
||
| 25 | |||
| 26 | try { |
||
| 27 | $response = $detailController(); |
||
| 28 | } catch (Exception $e) { |
||
| 29 | $response = HttpResponse::create('', HttpResponse::HTTP_FORBIDDEN); |
||
| 30 | } |
||
| 31 | |||
| 32 | $response->send(); |
||
| 33 |
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: