Alex Rivera | Logout

Extend Traits with Classes in PHP?

Asked 2012-04-07T17:06:06.163
38

Why we are not allowed to extend Traits with Classes in PHP?

For example:

Trait T { }

Class C use T {}
/* or */
Class C extends T {}

Is there any potential conflict for such syntax? I do not think so.

Edit
Report

1 Answer

8

Only classes can be extended. Traits are not classes. They can be used/included by classes but are not classes themselves. If you think a trait needs to be extended then it probably should be a class, probably an abstract one, and not a trait.

answered 2012-04-07T17:08:21.407

Your Answer