+ 10
What are Traits?
4 Answers
+ 8
Trait is a inheritance mechanism that let arrange functionalities in a convenient way. Multiple inheritance is not permited in PHP. So, alternate mechanism are used to extend the behaviour of a class, like interfaces and traits. A trait can't be instantiated by their own, as an abstract class in Java.
Here an example of Trait:
class Car {
    public function acelerate() {
        echo 'Car is acelerating ';
    }
}
trait MuscleCar {
    public function acelerate() {
        parent::acelerate();
        echo 'fast';
    }
}
class Camaro extends Car {
    use MuscleCar;
}
$c = new Camaro();
$c->acelerate();
The output is: 'Car is acelerating fast'
+ 8
hi whbe,i can see now only your message,same for nice to meet you and well play with java..i'm from india
+ 2
thanks sarath
+ 1
hello sarath, it is nice to meet you, i am from libya, and you