您好,登錄后才能下訂單哦!
<?php
/*
* 定義trait:test1
*/
trait test1{
public function sayhello(){
echo 'hello';
}
}
/*
* 定義trait:test2
*/
trait test2{
public function sayworld(){
echo 'world';
}
}
/*
* 定義類test,繼承自trait:test1,test2
*/
class test{
use test1,test2;
/*
* 定義類test的方法:sayhelloworld
*/
public function sayhelloworld(){
// 使用trait:test1中的sayhello方法
$hello = $this->sayhello();
// 使用trait:test2中的sayworld方法
$world = $this->sayworld();
echo $hello.$world;
}
}
// 實(shí)例化類test的對(duì)象objtest
$objtest = new test();
// 調(diào)用對(duì)象objtest的sayhelloworld方法
$objtest->sayhelloworld();
給大家推薦幾個(gè)好用的工具
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。