Traits Tutorial
<?php
trait hello
{
public function sayhello()
{
echo "Hello World" . "<br>";
}
public function sayhi()
{
echo "Hi Everyone" . "<br>";
}
}
trait bye
{
public function sayBye()
{
echo "Bye Bye Everyone" . "<br>";
}
public function takeCare()
{
echo "Take Care Everyone" . "<br>";
}
}
class Base
{
use hello, bye;
}
class Base2
{
use hello, bye;
}
$test = new Base();
$test->sayhello();
$test->sayBye();
$test->sayhi();
$test->takeCare();
$test2 = new Base2();
$test2->sayhello();
$test2->sayBye();
$test2->sayhi();
$test2->takeCare();
// OUTPUT:
//Hello World
// Bye Bye Everyone
// Hi Everyone
// Take Care Everyone
// Hello World
// Bye Bye Everyone
// Hi Everyone
// Take Care Everyone
?>
Comments
Post a Comment