PHP trait Keyword

PHP try Keyword
PHP throw Keyword

In this article, you will learn about the trait keyword in PHP. The trait keyword in PHP is used to create traits. Traits are a way to allow classes to inherit multiple behaviors.

examples of the TRAIT keyword

Example 1. In this example, we create a trait and use it in a class.

trait message1 {
  public function msg1() {
    echo "OOP is fun! ";

class Welcome {
  use message1;

$obj = new Welcome();
PHP try Keyword
PHP throw Keyword

Tutor Network

Share this

Learn PHP from A to Z