+ 10

What are Traits?

7th Jul 2017, 4:32 PM
Sarath Kumar
Sarath Kumar - avatar
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'
8th Jul 2017, 3:21 AM
⏩▶Clau◀âȘ
⏩▶Clau◀âȘ - avatar
+ 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
14th Jul 2017, 12:43 PM
Sarath Kumar
Sarath Kumar - avatar
+ 2
thanks sarath
14th Jul 2017, 10:27 PM
whbe
whbe - avatar
+ 1
hello sarath, it is nice to meet you, i am from libya, and you
13th Jul 2017, 2:26 AM
whbe
whbe - avatar