PHP Traits vs Interfaces OOPS use usages

Traits in php, Its having some default definition, let It be there, Now According to me its just to support multiple inheritance 

Say for example I'm Implementing a interface in class 

interface someinterface {
  public function somefunction();

}

 

class A implements someinterface {

  public function somefunction()  {

  }
}

This is an interface implements by class. 

Now See the below code. what do you think about it ?



interface someinterface {
  public function somefunction();

}


interface anotherinterface {
  public function someotherfunction();

}



class A implements someinterface, anotherinterface {

  public function somefunction()  {

  }

  public function someotherfunction() {

  } 
}

//Would it be possible in php ?

No, So to overcome this one, traits comes in place lets c how its possible

//Declaration of PHP Trait
trait thisistraitname
{
//Function traitFunction is the function which will be available in your trait
public function somefunctionintrait()
{
echo "This is callable by your class object";
}
}
//Declaring class where traits will be used
class A
{
use thisistraitname; //Adding things from the trait
}
$objTest = new A();
$objTest->somefunctionintrait();// Print This is callable by your class object

Now multiple Inheritance in php using traits which is not doable by interface

 

trait trait1 //declaration of first trait
{
public function func1()
{
echo 1;
}
}
trait trait2 //second trait
{
function func2()
{
echo 1;
}
}
class B
{
use trait1 , trait2;
}


$b = new B();
$b->func1();
$b->func2();

Thats it, will have more about traits in my next article bye.