ایک trait متعدد کلاسز میں کوڈ کو دوبارہ استعمال کرنے کا ایک طریقہ ہے جو وراثت سے منسلک نہیں ہیں۔ چونکہ PHP صرف single inheritance کی اجازت دیتا ہے، traits افقی انداز میں methods (اور properties) کو شیئر کرنے کا ایک طریقہ فراہم کرتے ہیں — یہ "compositional" کوڈ کی دوبارہ استعمال کی شکل ہے، جیسے mixins۔
Traits جو مسئلہ حل کرتے ہیں
PHP has single inheritance — a class can extend only ONE parent. But you often want
to share the SAME methods across unrelated classes (e.g. logging, timestamps).
Duplicating the code is bad; traits let you reuse it without inheritance.
