Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-08T22:46:41.743Z
Answers.Text: Thanks - I wasn't aware of behaviours so will take a look at that first.
Answers.UserDisplayName: Russ Back
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-08T22:42:32.843Z
Answers.LastActivityDate: 2015-04-08T22:42:32.843Z
Answers.UserDisplayName: Brad Bell
Body: <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>
  
Tags: <plugin-development>
Title: Can traits be loaded in plugins?
ThreadText: # 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 username_0 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.  
  
  ---
  
  