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

GROUP BY Clause and HAVING Clause in PHP

Mysqli database Connection and Display Table Data from Database