Bug #62042 [Opn->Fbk]: Fatal error when merging files due to class/function/symbol name collision
| From: | cmb@php.net | Date: | Mon, 26 Jul 2021 13:53:07 +0000 |
| Subject: | Bug #62042 [Opn->Fbk]: Fatal error when merging files due to class/function/symbol name collision | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-235367@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62042&edit=1
ID: 62042
Updated by: cmb@php.net
Reported by: phplists at stanvassilev dot com
Summary: Fatal error when merging files due to
class/function/symbol name collision
-Status: Open
+Status: Feedback
Type: Bug
Package: Unknown/Other Function
Operating System: All
PHP Version: 5.3.13
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
For reference: <https://3v4l.org/8iZWh>.
> [â¦] but once they're merged in the same file [â¦]
I don't see much point in doing that; use autoloading and OPcache.
Previous Comments:
------------------------------------------------------------------------
[2014-01-20 17:28:33] phplists at stanvassilev dot com
To "HMWiesinger at liwjatan dot at":
Those aren't class names, but local aliases, which are scoped only to a namespace declaration.
This is the entire point of namespace aliases, that they're not global.
An alias declared in one namespace block doesn't work in another. So it makes no sense to check
for alias uniqueness across namespace blocks at global level or file level, but at namespace block
level.
It's a bug.
The correct solution is no fatal errors.
------------------------------------------------------------------------
[2014-01-20 16:51:40] HMWiesinger at liwjatan dot at
IMHO the correct behavior would be to throw a fatal error in all scenarios. Identifiers need to be
unique. When declaring the same class in two separate files you get a name conflict as well, so I
don't get why you shouldn't get one with namespace aliases either.
------------------------------------------------------------------------
[2013-03-18 19:17:11] joseaugustodearaujonascimento at gmail dot com
The same problem arises when in a two namespace context.
# File: App\N2\Foo.php
namespace App\N2;
use App\N1\Bar;
class Foo
{
}
# File: App\N2\Bar.php
namespace App\N2;
class Bar
{
}
# File: App\N1\Bar.php
namespace App\N1;
class Bar
{
}
Using Bar of App\N1 cause the same problem.
I think that the use in App\N2\Foo.php should only be valid on the App\N2\Foo
class context and not reflected on the entire
namespace as the error message suggest.
------------------------------------------------------------------------
[2012-05-15 21:05:08] phplists at stanvassilev dot com
Description:
------------
These two namespaces work as expected when in two separate files, and when
included together at runtime work as expected as well, but once they're merged
in the same file they result in a Fatal Error:
namespace Foo {
class Bar {}
}
namespace Foo {
use Bar;
}
Fatal error: Cannot use Bar as Bar because the name is already in use.
I understand this behavior was introduced with good intentions, but all it does
is break working code when files are merged together. The alternative namespace
construct was introduced specifically to support merging of multiple files
together without side effects, and this is such a side effect.
Expected result:
----------------
I expect that "use" statements should override default resolutions, and no Fatal
Error should be produced (the EXACT behavior we have right now when the above is
spread in two files which are required() at runtime).
Actual result:
--------------
Fatal Error when merging code.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62042&edit=1