Bug #63652 [Opn->Nab]: Using twice the same trait causes fatal error.
| From: | laruence@php.net | Date: | Mon, 03 Dec 2012 09:16:25 +0000 |
| Subject: | Bug #63652 [Opn->Nab]: Using twice the same trait causes fatal error. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-175079@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63652&edit=1
ID: 63652
Updated by: laruence@php.net
Reported by: stealz at op dot pl
Summary: Using twice the same trait causes fatal error.
-Status: Open
+Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Windows 7
PHP Version: 5.4.9
Block user comment: N
Private report: N
New Comment:
use a triat means copy the methods of traits into the dst class table.
so, they are not the same method after copied.
Previous Comments:
------------------------------------------------------------------------
[2012-12-01 14:05:28] stealz at op dot pl
Thank you for your reply.
PHP had warned me indeed, but it doesn't change the fact that, as I wrote, this is exactly the
same method of exactly the same trait, so it shouldn't be colliding at all.
Can you please prove me wrong?
------------------------------------------------------------------------
[2012-12-01 05:52:37] laruence@php.net
I think PHP had warn you about method collisions..
------------------------------------------------------------------------
[2012-12-01 05:52:32] laruence@php.net
I think PHP had warn you about method collisions..
------------------------------------------------------------------------
[2012-11-30 01:48:47] stealz at op dot pl
Description:
------------
I think PHP should check whether traits were used already (ex. in parent class) and ignore them
instead using again. It causes fatal error due to collisions which are obvious, because trait name
is the same.
What's interesting, collisions refer only to methods. PHP seems not to see the problem if
double-used trait contains properties only.
Test script:
---------------
trait LifeOrganism {
public $age; // it's fine
#public function live() {} // uncomment to get Fatal error
}
trait Man {
use LifeOrganism;
}
trait Elephant {
use LifeOrganism;
}
class ElephantMan {
use Man, Elephant;
}
Expected result:
----------------
Ignore trait which was already used.
Actual result:
--------------
Fatal error.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63652&edit=1