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 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊