1.

What are traits? How is it used in PHP?

Answer»

A trait is a group of various methods that reuse in SINGLE inheritance. A Trait is intended to REDUCE some LIMITATIONS of single inheritance by enabling a developer to reuse sets of processes. We can combine traits and classes to reduce complexity, avoid PROBLEMS typically associated with Mixins and multiple inheritances.

Related Article: How to USE Traits in PHPExample

trait HelloWorld
{
     use Hello, World;
}
class MyWorld
{
     use HelloWorld;
}
$world = new MyWorld();
echo $world->sayHello() . " " . $world->sayWorld(); //Hello World



Discussion

No Comment Found