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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
37 - 23 = ?
Subscribe to this entry?

 
 [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: Mon Apr 29 16:01:31 2024 UTC