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 »
The trait
keyword is used to create traits. Traits are a way to allow classes to inherit multiple behaviours.
Read more about traits in our PHP OOP - Traits Tutorial.
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!