作者kenit (充实自己实现梦想)
看板PHP
标题[请益] 转换回传物件
时间Fri Jan 11 11:46:32 2013
我有三个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();
但语法错误
请各位先进指导指导 甘温~
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.202.81.67