PHP use Keyword

PHP var Keyword
PHP try Keyword

In this article, you will learn about use keyword. The use keyword in PHP has two purposes: it tells a class to inherit a trait and it gives an alias to a namespace.

examples of the USE keyword

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

<?php
trait message1 {
  public function msg1() {
    echo "OOP is fun! ";
  }
}

class Welcome {
  use message1;
}

$obj = new Welcome();
$obj->msg1();
?>
PHP var Keyword
PHP try Keyword
en English
X
Scroll to Top