Skip to content
Bullshit Driven Development
  • Home

#trait

PHP Traits: How to Use Them the Right Way

Posted on 15 August 2026 by Hałas Piotr

There are many ways to stop code duplication in classes. The simplest way is inheritance. But what if a class needs code from many different classes? PHP does not allow multiple inheritance. So the only way is to use traits. A good trait works well in any class. This post shows you how to write a good trait.

Continue readingPHP Traits: How to Use Them the Right Way

© 2026 Writings Theme. Powered by WordPress.