doukuilian8365 2016-04-12 00:58
浏览 28
已采纳

扩展如何在类中工作?

I've been trying to build a PDO extension, and I wanted to have special classes in different files but I wanted to have them all link to the same original class.

I have worked with some Frameworks and I see that they use the extends class keyword, and I thought that it added the class you are making to the class that you have given.

Some code I have tried is:

class PSMQuery extends PSM {

   // Functions and Jargon

}

I tried making an object for the original PSM class:

$psm = new PSM(/*Information*/);

But when I call the $psm variable like $psm->functionInTheExtendedClass it comes up with an error saying that it was an undefined method when I called it.

Am I using the extends keyword incorrectly?

  • 写回答

2条回答 默认 最新

  • dqblm40280 2016-04-12 01:05
    关注

    Am I using the extends keyword incorrectly?

    You use it correctly, but it works the other way around.

    If PSMQuery extends from PSM, this means you can access and use stuff from PSM in PSMQuery, but not the other way around.

    I think to understand it you can use a good example:

    class twoRoomApartment extends building { }
    

    So now you can think logical and already see, that a two room apartment probably extends from a building and not the other way around.

    Means now in your code, you just create an instance of PSMQuery.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答