Skip to content

Conversation

AndreiDreyer
Copy link
Contributor

use Trait in Php acts like interfaces that allow you to override methods or call the base method implemented in the trait. We simply add the trait name to the inheritsFrom field. It's also been tested, the use Trait call can be anywhere in the class definition but still acts like it was called at the top of the class definition.

trait TraitA {
  function traitFunc() {}
}

class Foo {
  use TraitA;
  function someFunc() {
    $this->traitFunc();
  }
}

(new Foo()).traitFunc();

@AndreiDreyer AndreiDreyer requested a review from ml86 July 30, 2025 13:07
@AndreiDreyer AndreiDreyer self-assigned this Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants