运行 ❯
获取
您的 PHP
服务器
×
变更方向
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <?php trait message1 { public function msg1() { echo "OOP is fun! "; } } trait message2 { public function msg2() { echo "OOP reduces code duplication!"; } } class Welcome { use message1; } class Welcome2 { use message1, message2; } $obj = new Welcome(); $obj->msg1(); echo "<br>"; $obj2 = new Welcome2(); $obj2->msg1(); $obj2->msg2(); ?> </body> </html>
面向对象编程很有趣!
面向对象编程很有趣!面向对象编程减少了代码重复!