Posts
Showing posts from July, 2017
Understanding Traits in PHP
- Get link
- X
- Other Apps
Traits is the mechanism implemented to reuse code in PHP. Traits are mainly introduced to reduce limitations that caused by single inheritance. PHP does not support multiple inheritances. In traits, we can use methods from traits in different classes, which compensate multiple inheritance features. From above example, If we want to use class C functionality to both D and E classes it is not possible that is the reason in PHP 5.4 traits concepts are introduced. Let see an example by using traits