trait คือกลไกสำหรับ การใช้โค้ดซ้ำข้ามหลายคลาส ที่ไม่ได้มีความสัมพันธ์กันผ่าน inheritance เนื่องจาก PHP อนุญาตเพียง single inheritance trait จึงเป็นวิธีแบ่งปันเมธอด (และ property) ในแนวนอน เป็นรูปแบบหนึ่งของการใช้โค้ดซ้ำแบบ "compositional" คล้ายกับ mixin
ปัญหาที่ trait แก้ไข
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.
