作者tkdmaf (皮皮快跑)
看板PHP
标题Re: [请益] 转换回传物件
时间Fri Jan 11 15:02:11 2013
※ 引述《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