1銆佷粈涔堟槸閫傞厤鍣ㄦā寮忥紵
閫傞厤鍣ㄨ璁℃ā寮忓彧鏄皢鏌愪釜瀵硅薄鐨勬帴鍙i傞厤涓哄彟澶栦竴涓璞℃墍鏈熸湜鐨勬帴鍙
2銆佸疄渚嬭瑙
<?php
/*
* 閫傞厤鍣ㄨ璁℃ā寮
* --------------
* @author liuxinming
*/
/*鏃╁厛璁捐鐨勪竴涓被*/
class UserInfo{
/**
* 鏍规嵁鐢ㄦ埛UID鑾峰彇鐢ㄦ埛淇℃伅
* @param inti $uid 鐢ㄦ埛ID
* @return array $userinfo 杩斿洖鐢ㄦ埛淇℃伅
*/
public function getUserInfo($uid){
//鐩稿叧澶勭悊
//DB灞傦紝浠庢暟鎹簱鏌ヨ鐢ㄦ埛淇℃伅
$userinfo=array(
'uid'=>1,
'username'=>'liuxinming',
);
return $userinfo;
}
}
/**
* 閫傞厤鍣ㄧ被锛岀洰鐨勬槸鍦ㄦ柊闇姹傚鍔犵殑鎯呭喌 涓嶄慨鏀逛互鍓嶅叕鍏辨帴鍙g被锛岄氳繃瀵归傞厤鍣║serInfoIntegral鐢ㄦ埛绉垎绫荤殑鎵╁睍鏉ユ弧瓒虫柊闇姹
*/
class UserInfoIntegral extends UserInfo{
public function getUserIntegral($uid){
$integral=array(
'integral1'=>2,
'integral2'=>3,
);
return $integral;
}
public function getUser($uid){
$userall=array(
'userinfo'=>$this->getUserInfo($uid),
'userintegral'=>$this->getUserIntegral($uid),
);
return $userall;
}
}
/**
* 鑾峰彇鐢ㄦ埛淇℃伅瀹㈡埛绔被
*/
class MyObject{
public function write($uid){
$UserInfoApp= new UserInfoIntegral();
return $UserInfoApp->getUser($uid);
}
}
$l=new MyObject();
print_r($l->write(1));
?>
杩愯鍚庤緭鍑哄涓嬶細
Array (
[userinfo] => Array (
[uid] => 1
[username] => liuxinming
)
[userintegral] => Array (
[integral1] => 2
[integral2] => 3
)
)
浠ヤ笂灏辨槸PHP涔嬭璁℃ā寮忊旈傞厤鍣ㄦā寮忕殑璇︾粏鍐呭锛屾洿澶氫俊鎭鍏虫敞OD浜戝叾瀹冪浉鍏虫枃绔狅紒