How can traits be used in PHP to avoid method name conflicts?

Traits can be used in PHP to avoid method name conflicts by allowing developers to reuse methods across multiple classes without the need for inheritance. By using traits, you can define common methods in a trait and then include that trait in multiple classes, preventing conflicts that may arise from method name duplications.

trait CommonMethods {
    public function method1() {
        // implementation for method1
    }

    public function method2() {
        // implementation for method2
    }
}

class Class1 {
    use CommonMethods;

    // Class1 specific methods
}

class Class2 {
    use CommonMethods;

    // Class2 specific methods
}