Method Overriding in Traits in PHP

 <?php

class Base
{
    public function abc()
    {
        echo "ABC method from Base class.";
    }
}
//The trait method(Here, abc() Method) will get priority compared to Parent class Method(Here, abc() Method)
trait Test
{
    public function abc()
    {
        echo "ABC method from test trait.";
    }
}
class Child extends Base
{
    use Test;
    public function abc()
    {
        echo "ABC method from Child class.";
    }
}
$obj = new Child();
$obj->abc();



Comments

Popular posts from this blog

Logical_Operators

SubQuery with EXISTS and NOT EXISTS in PHP

Get Functions