Edit report at https://bugs.php.net/bug.php?id=62069&edit=1
ID: 62069
Updated by: nikic@php.net
Reported by: laruence@php.net
Summary: binding wrong traits if they have same name methods
-Status: Assigned
+Status: Closed
Type: Bug
Package: Scripting Engine problem
PHP Version: 5.4.3
Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Fixed by https://github.com/php/php-src/commit/fff5771cccaca49565c90349320f3c06cbe19328
in master. The code will now throw a fatal error and require explicit disambiguation using T1::func
or T2::func.
Previous Comments:
------------------------------------------------------------------------
[2020-03-06 10:21:21] nikic@php.net
Related To: Bug #74872
------------------------------------------------------------------------
[2012-05-22 08:38:24] dmitry@php.net
I agree that syntax "use T1 {func as f1;}" where "func" belong to another trait
looks unnatural, and it's better to interpret "func" as "T1::func" in this
case, but it won't solve the problem in general, because it's possible to refer few traits
in a single "use" statement.
------------------------------------------------------------------------
[2012-05-22 07:17:55] gron@php.net
Sorry, I don't have the time to look into the code.
But I guess, I compiled the 'as' of 'use T1 { func as f1; }' without the
information of being related to T1.
If the compilation step would automatically add the T1 to 'as' for 'use'
statements with only a single trait, this particular bug here would be solved.
It does not solve the ambiguity however.
Not sure what to do with that.
I still think it is convenient, to be able to leave out the T1:: infront of the
method name.
------------------------------------------------------------------------
[2012-05-22 06:25:47] dmitry@php.net
I would say it's not an implementation bug, but design mistake that allows ambiguous syntax.
The problem that class may include several "use" statements, each statement may refer
several traits and each such statement may be followed by a block with alias declarations. However,
all these blocks have equal rights and it doesn't mean which traits were used in
"use" statement before.
So the second example is treated as:
use T1, T2 {
func as f1;
func as f2;
}
To refer to the proper traits methods need to be qualified
use T1, T2 {
T1::func as f1;
T2::func as f2;
}
I'll try to take a look, if it's possible to fix it, but I don't think it's
possible to do it in 5.4 (without binary compatibility break).
------------------------------------------------------------------------
[2012-05-22 02:24:52] laruence@php.net
@dmitry, as a common guess, the second should have a high priority, I think it
should be a bug ... :)
------------------------------------------------------------------------
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=62069
--
Edit this bug report at https://bugs.php.net/bug.php?id=62069&edit=1