1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | use RssApp\Bootstrap; |
||
6 | use RssApp\Controller; |
||
7 | use RssApp\RequestBootstrap; |
||
8 | use Spiral\Debug; |
||
0 ignored issues
–
show
|
|||
9 | |||
10 | define("BASEPATH", dirname(__FILE__)); |
||
11 | define("DS", DIRECTORY_SEPARATOR); |
||
12 | |||
13 | require_once BASEPATH.DS.'external'.DS.'autoload.php'; |
||
14 | |||
15 | define("APPLICATION_ENV", getenv("APPLICATION_ENV") ?? 'dev'); |
||
16 | |||
17 | $dumper = new Debug\Dumper(); |
||
18 | $dumper->setRenderer(Debug\Dumper::ERROR_LOG, new Debug\Renderer\ConsoleRenderer()); |
||
19 | function dump($msg) { |
||
20 | global $dumper; |
||
21 | $dumper->dump($msg, Debug\Dumper::ERROR_LOG); |
||
22 | } |
||
23 | |||
24 | try { |
||
25 | Bootstrap::initialize(); |
||
26 | } catch (Exception $e) { |
||
27 | dump("Problem with application bootstrap: ".$e->getMessage()); |
||
28 | } |
||
29 | |||
30 | $relay = new Spiral\Goridge\StreamRelay(STDIN, STDOUT); |
||
31 | $psr7 = new Spiral\RoadRunner\PSR7Client(new Spiral\RoadRunner\Worker($relay)); |
||
32 | while ($req = $psr7->acceptRequest()) { |
||
33 | try { |
||
34 | RequestBootstrap::initialize(); |
||
35 | $resp = Controller::handle(); |
||
36 | $psr7->respond($resp); |
||
37 | } catch (Throwable $e) { |
||
38 | $psr7->getWorker()->error((string) $e); |
||
39 | } |
||
40 | } |
||
41 |
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: