php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63652 Using twice the same trait causes fatal error.
Submitted: 2012-11-30 01:48 UTC Modified: 2012-12-03 09:16 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: stealz at op dot pl Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.4.9 OS: Windows 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: stealz at op dot pl
New email:
PHP Version: OS:

 

 [2012-11-30 01:48 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-01 05:52 UTC] laruence@php.net
I think PHP had warn you about method collisions..
 [2012-12-01 05:52 UTC] laruence@php.net
I think PHP had warn you about method collisions..
 [2012-12-01 14:05 UTC] 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-03 09:16 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 [2012-12-03 09:16 UTC] laruence@php.net
use a triat means copy the methods of traits into the dst class table.

so, they are not the same method after copied.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 11:01:29 2024 UTC