Bug #66773 [Com]: Autoload with Opcache allows importing conflicting class name to namespace
| From: | Erutan409 at Hotmail dot com | Date: | Tue, 02 Jun 2015 13:53:55 +0000 |
| Subject: | Bug #66773 [Com]: Autoload with Opcache allows importing conflicting class name to namespace | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-193070@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66773&edit=1
ID: 66773
Comment by: Erutan409 at Hotmail dot com
Reported by: carl dot vuorinen at w3 dot fi
Summary: Autoload with Opcache allows importing conflicting
class name to namespace
Status: Assigned
Type: Bug
Package: opcache
Operating System: Linux (Ubuntu)
PHP Version: 5.5.9
Assigned To: dmitry
Block user comment: N
Private report: N
New Comment:
Has this been resolved, yet and/or is this still considered a bug?
Previous Comments:
------------------------------------------------------------------------
[2014-11-07 17:15:44] john at zerocrates dot org
Isn't the "expected" error behavior here directly in conflict with the documentation?
http://php.net/manual/en/language.namespaces.faq.php#language.namespaces.faq.conflict
That documentation section gives the following example:
file1.php
---------
<?php
namespace my\stuff;
class MyClass {}
?>
another.php
-----------
<?php
namespace another;
class thing {}
?>
file2.php
---------
<?php
namespace my\stuff;
include 'file1.php';
include 'another.php';
use another\thing as MyClass;
$a = new MyClass; // instantiates class "thing" from namespace another
?>
So, in file2.php, once the includes are done, the class name "my\stuff\MyClass" is already
"in use." But, the documentation says that the "conflicting" use statement
"use another\thing as MyClass" should be fine, so long as the other MyClass is declared in
another file (which it is). On this subject the documentation says:
"There is no name conflict, even though the class MyClass exists within the my\stuff namespace,
because the MyClass definition is in a separate file."
Other than the use of autoloading, I can't see any distinction between that example and the
test script here, and it doesn't seem like the autoloading should make any difference.
------------------------------------------------------------------------
[2014-10-23 15:40:45] nikic@php.net
I think all we need to do is drop the if (+ 10 lines) at http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_compile.c#4723,
which checks whether a class with the imported name already exists.
------------------------------------------------------------------------
[2014-10-23 11:39:09] dmitry@php.net
Nikta, it would be great if you can take care about this.
I completely forgot namespaces implementation details.
I'm even not sure, if it can be done without hacks.
------------------------------------------------------------------------
[2014-10-23 10:07:33] nikic@php.net
I agree with Dmitry, it would be best to allow shadowing class definitions with imports in PHP 7.
The current behavior is pretty weird, especially as it depends on the order in which classes are
loaded.
------------------------------------------------------------------------
[2014-10-23 09:17:47] dmitry@php.net
Unfortunately, the patch is wrong.
Opcache compiles each script separately by design.
Otherwise, it'll may make dependencies on other scripts.
And later to unpredictable behavior, if some of those scripts are changed and recompiled but
depended is not.
The patch breaks this rule.
Actually, the behavior with opcache seems better :)
May be it makes sense switching to it in PHP7.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=66773
--
Edit this bug report at https://bugs.php.net/bug.php?id=66773&edit=1