dongyuxiao6295 2012-08-25 08:31
浏览 38

在PHP中通过另一个扩展类加载类时遇到问题

I have three class: A, B and C. In class A, A.php:

class A
{
    function __Contruct()
    {
          //do something
    }
}

In class B, B.php:

class B extends A
{
    function __Contruct()
    {
         //do something
    }
}

In class C:

class C
{
    function __Contruct()
    {
         include(A.php);
         $this->A = new A;
         include(B.php);
         $this->B = new B;
    }
    function _load()
    {
         //load class $X;
    }
}

I need to load a class whose name is value of a variable:$X to class without word new in class B.

Can I do it this way:$this->classname->functionname();//classname is value of $X in file B.php.

  • 写回答

2条回答 默认 最新

  • dongyizhuang0134 2012-08-25 08:49
    关注

    You extend class B with class A, so why didn't you extend class C with class B? Then you can access all properties & methods of class A and class B.

    No need of

    $this->classname->functionname();
    

    or you can access method or property as follows,

    A::functionname();
    B::functionname();
    C::functionname();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测