2

Who can explain better traits and method in php?

Comments
  • 2
    Plain basics (oversimplified for better understanding):

    Method = function inside of a class
    Trait = a piece of class which you include inside of a multiple classes to reuse the code better and don't repeat yourself, made specifically cause there's no multiple inheritance in php
  • 1
  • 0
    Trait is like a reusable method that you can use in a class? It’s been a while but that’s how I viewed it
  • 0
    @bashleigh can containt all the other stuff which normal class holds, not just method
  • 0
    Yes? You can add properties but I think they might have to be public/protected? Not sure they can be private? Can’t remember? But if you can do something, use an abstract or instance
Add Comment