Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • 2
    I am putting into a comment since it doesn't exactly answer your question. Anyway. There is no way to ensure things like that because trait is not part of the class. You can think of it (it's a bit oversimplified) as of an include for classes. It is a simple way of doing copy/paste without code duplication. If you have a shared functionality in your trait then this trait should already have everything to work by itself. If it doesn't you might already have some conceptual issues. Commented Jun 28, 2015 at 18:12
  • Thanks awons. Reviewing what I was doing at the time I did have a couple of conceptual problems. Commented Aug 17, 2015 at 21:49
  • Stop and think for a moment why you think you need a trait in the first place. Traits cannot enforce properties, the same reason you cannot put properties on interfaces in PHP. Traits should be your last resort, dont use them if you dont have to. Commented Mar 16, 2020 at 5:49