1A Trait, like an abstract class cannot be instantiated by itself.Trait are created to reduce the limitations of single inheritance in PHP by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies.
2
3Here is an example of trait.
4
5trait Sharable {
6
7 public function share($item)
8 {
9 return 'share this item';
10 }
11
12}
13You could then include this Trait within other classes like this:
14
15
16class Post {
17
18 use Sharable;
19
20}
21
22class Comment {
23
24 use Sharable;
25
26}
27