Use-case for `use`ing the same trait multiple times in the same class?
| From: | Levi Morrison | Date: | Mon, 04 Dec 2017 17:26:12 +0000 |
| Subject: | Use-case for `use`ing the same trait multiple times in the same class? | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-101227@lists.php.net to get a copy of this message | ||
Currently we permit the same trait to be
used multiple times in a class:
```php
trait T { }
class C {
use T;
use T;
}
```
In this example it works because T doesn't have any methods.
If you add methods it won't because they will conflict:
```php
trait T { function get() {} }
```
> Trait method get has not been applied, because there are collisions with other trait methods
The main question for this email: are there any valid use-cases which
do not conflict? Is there some way the methods *on the same class*
don't conflict? Using T::get as get2 still conflicts because that
*aliases* even though most literature says it renames.
If not I would like to forbid it as part of an implementation of
generics I am working on.