DEV Community

Discussion on: How to Use PHP Traits

megusta420 profile image
hi panda

So, guys, what do you think about that traits in PHP is not good practice because of a couple of arch reasons (better using of abstract classes)? Also, what do you think about why for example Vue JS proposes mixins as good practice? Discuss.

paulthebaud profile image
Paul Thébaud

I don't know Vue JS mixins, but about PHP, here is my opinion :
Traits are not a bad practice, but they must be used carefully. I mean, you can use them for several things (I think about the RefreshDatabase trait in Laravel testing env), but it is not a good practice to use them to add property in your class (such as adding a name on your class Person for exemple).