Re: [請益] 轉換回傳物件

看板PHP作者 (皮皮快跑)時間13年前 (2013/01/11 15:02), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
※ 引述《kenit (充實自己實現夢想)》之銘言: : 我有三個class : A,B,BB : BB繼承B : 然後A裡面有一個method getB() 會回傳一個B的instance : 也就是 : class A{ : private $b; : public function __construct(){ : $this->b= new B(); : } : public function getB(){ : return $this->b; : } : } : 假設$a = new A(); : 請問我可以將 $a->getB()回傳的物件 : 轉換成BB的物件嗎? : 我異想天開的試過$bb= (BB) $a->getB(); : 但語法錯誤 : 請各位先進指導指導 甘溫~ class A{ private $b; public function __construct($object){ $this->b= $object; } public function getB(){ return $this->b; } } $a = new A(new BB); $bb = $a->getB(); -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.136.34.247
文章代碼(AID): #1GxxZtSF (PHP)
討論串 (同標題文章)
文章代碼(AID): #1GxxZtSF (PHP)