将对象强制转换为扩展母类的子类

时间:2014-11-21 00:45:05

标签: php

我试图通过扩展它,然后将对象强制转换为我的子扩展类来为类添加一个方法:

public class motherClass(){
  public function methodA(){}
}

public class childClass extends motherClass (){
  public function methodB(){}
}


$obj= Method that return an istance of motherClass
$objChild = (childClass) $obj;
$objChild->methodB();

可以在PHP中执行此操作吗? 我需要安装$ objChild因为我想在属于motherClass的对象中从childClass调用一些方法。

0 个答案:

没有答案
相关问题