PHP use Keyword
Example
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();
?>
Try it Yourself »
Definition and Usage
The use
keyword has two purposes: it tells a class to inherit a trait and it gives an alias to
a namespace.
Related Pages
Read more about traits in our PHP OOP - Traits Tutorial.
Read more about namespaces our PHP Namespaces Tutorial.
❮ PHP Keywords
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.