dongwen1909 2012-01-10 16:25 采纳率: 0%
浏览 118
已采纳

是否可以替换PHP类中的函数?

This is actually comes from a specific WordPress issue but there's a more general PHP point behind it which I'm interested to know the answer to.

The WordPress class is along these lines:

class Tribe_Image_Widget extends WP_Widget {
    function example_function(){
        // do something useful
    }
}

Is there any way in PHP that I can replace example_function() from outside the class?

The reason I want to do this is that the class is from someone else's WP plugin (and has several functions in the class) and I want to continue receiving updates to the plugin but I want one of the functions adapted. If I change the plugin, then I'll lose all my own changes each time. SO if I have my own plugin which just changes that one function, I avoid the problem.

  • 写回答

3条回答 默认 最新

  • dqroc48068 2012-01-10 16:28
    关注

    It sounds like what you want to do is extend the class, and override that particular function.

    Class Your_Tribe_Image_Widget extends Tribe_Image_Widget
    {
       function example_function() {
         // Call the base class functionality
         // If necessary...
         parent::example_function();
    
         // Do something else useful
       }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 nginx的使用与作用
  • ¥100 关于#VijeoCitect#的问题,如何解决?(标签-ar|关键词-数据类型)
  • ¥30 数字信号处理实验报告
  • ¥15 一个矿井排水监控系统的plc梯形图,求各程序段都是什么意思
  • ¥15 ensp路由器启动不了一直报#
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?
  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 数学建模数学建模需要