Example
Create a trait and use it in a class:
html
<?php
trait message1 {
public function msg1() {
echo
"OOP is fun! ";
}
}
class Welcome {
use
message1;
}
$obj = new Welcome();
$obj->msg1();
?>
Definition and Usage
The trait keyword is used to create traits. Traits are a way to allow classes to inherit multiple behaviours.