PHP

Use trait: Stop abuse inheritance in PHP

In PHP, a trait is a mechanism for code reuse in single inheritance languages. You can use traits to group functionality in a fine-grained and consistent way. Here’s a convention way to used same thing over and over again for different classes

class MyClass1 {
   public function MyActivity ($body){ 
         // add a new activity 
    }
}

class MyClass2 {

    public function MyActivity ($body){ 
         // add a new activity 
    }
}

Now see the magic of trait .

train Activity {

    public function MyActivity ($body){ 
         // add a new activity 
    }
}

class MyClass1 {
use MyActivity ; 
}

class MyClass2 {
use MyActivity ; 
}

see!! PHP is cool !! i love you PHP