1.

What is traits? How it is used in php?

Answer»

TRAITS is a group of 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 methods.

Example

trait HelloWorld

{

USE HELLO, World;

}

class MyWorld {

use HelloWorld;

}

$world = new MyWorld();

echo $world->sayHello() . " " . $world->sayWorld(); //Hello World



Discussion

No Comment Found