Access Levels in Traits in PHP

 <?php

trait abc
{
    private function xyz()
    {
        echo "XYZ method from trait abc";
    }
}
class test
{
    use abc {
        abc::xyz as public;    //Changing the Access Modifier from private to public of Method xyz()
        abc::xyz as public abcXYZ;  //Changing the Access Modifier from private to public of method xyz()
        // as well as Changing the name of method xyz() to abcXYZ()
    }
}
$obj = new test();
$obj->xyz();
echo "<br><br>";
$obj->abcXYZ();


Comments

Popular posts from this blog

Ajax Insert Records in Database Tutorial in PHP

Displaying Database data using Class, Object, Constructor, Destructor in PHP MySql

SubQuery with EXISTS and NOT EXISTS in PHP