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();
.png)
Comments
Post a Comment