trait in php example
<?php
/**
* Inheritance in unnecessary function is also called we we don't require them, so we can prevent them using traits
* Trait is only available when we use them otherwise not!
*/
trait A
{
function fun1()
{
echo "class A called";
}
}
class B
{
use A;
function fun2()
{
echo "class B called";
}
}
class C extends B
{
function fun3()
{
echo "class C called";
}
}
class D extends C
{
use A;
function fun4()
{
echo "class D called";
}
}
$obj = new C();
$obj->fun1();
?>