PHP:如何从子类更新父类的变量 [英] PHP: How to update a variable of a parent class from a child class

查看:45
本文介绍了PHP:如何从子类更新父类的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在子类中有一个函数,该函数计算页面加载中SQL查询的数量

I have a function in a child class which counts the number of SQL queries in a page load

在扩展父类的子类中,每执行一次: mysql_query($ query);

In the child class which extends the parent class, after every: mysql_query($query);

我把 parent :: update_query_function();

其中 update_query_function()是:

function update_query_function(){

$this->query_num++;

}

父类中的

$ query_num 变量未更新.为什么?

the $query_num variable in the parent class is not being updated. Why?

推荐答案

如果您的子类扩展了父类,则无需这样做,而是这样做:

If your child class extends the parent class there's no need to do that, do this instead:

$this->update_query_function();

那是继承的重点.

这篇关于PHP:如何从子类更新父类的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆