Traits are a [[Programming|programming]] concept, that describes a way of implementing [[Composition]] in languages that do not have multiple-inheritance. [[PHP]] does not have multiple inheritance, so it uses Traits a lot. It implements [PSR-12](https://www.php-fig.org/psr/psr-12/)
Essentially, you auto copy and paste the interior of the Trait into the target class it's used on.
This means that namespace collisions can occur if a function is named the same. There's no way to overload a trait function.
## [[PHP]] Example
```php
trait TraitName {
// some code...
function some_function();
}
class MyClass {
use TraitName;
}
```
---
# References