<p><a href="https://php.net/manual/en/language.oop5.traits.php" rel="nofollow">Traits</a> are just a PHP thing not related to Craft at all so yes, you could use them.  But you'd be limiting your plugin to PHP 5.4+ only since that's when they were introduced.</p>

<p>Craft 2.x supports back to <a href="http://buildwithcraft.com/docs/requirements#server-requirements" rel="nofollow">PHP 5.3</a>.</p>

<p>You might also want to look at Yii's <a href="http://www.yiiframework.com/wiki/44/behaviors-events/#hh1" rel="nofollow">Behaviors</a>, which have similar functionality to traits and works with PHP 5.3.</p>

<p>Craft 2.x uses a <a href="http://buildwithcraft.com/classreference#craft.app.etc.behaviors" rel="nofollow">few behaviors</a> of its own.</p>

CC BY-SA 3.0
2015-04-08T22:46:41.743Z
Thanks - I wasn't aware of behaviours so will take a look at that first.
Russ Back
CC BY-SA 3.0
2015-04-08T22:42:32.843Z
2015-04-08T22:42:32.843Z
Brad Bell
<p>I have a number of different models that have custom validation methods, some of which are shared across models.</p>

<p>Due to the combinations I can't use class inheritance to share those methods, so I wondered if traits are supported and if so, what the convention would be?</p>

<plugin-development>
Can traits be loaded in plugins?
# Can traits be loaded in plugins?

(Asked by: username_0 on 2015-04-08)

I have a number of different models that have custom validation methods, some of which are shared across models.

Due to the combinations I can't use class inheritance to share those methods, so I wondered if traits are supported and if so, what the convention would be?

**Tags:** plugin-development


---

## 1 answers

### Answer by username_1 on 2015-04-08. Score: 1 | Accepted answer

[Traits](https://php.net/manual/en/language.oop5.traits.php) are just a PHP thing not related to Craft at all so yes, you could use them. But you'd be limiting your plugin to PHP 5.4+ only since that's when they were introduced.

Craft 2.x supports back to [PHP 5.3](http://buildwithcraft.com/docs/requirements#server-requirements).

You might also want to look at Yii's [Behaviors](http://www.yiiframework.com/wiki/44/behaviors-events/#hh1), which have similar functionality to traits and works with PHP 5.3.

Craft 2.x uses a [few behaviors](http://buildwithcraft.com/classreference#craft.app.etc.behaviors) of its own.

> **Comments:**
> **username_0**: Thanks - I wasn't aware of behaviours so will take a look at that first.  

---

