[英]PHP: How to update a variable of a parent class from a child class
I have a function in a child class which counts the number of SQL queries in a page load 我在子类中有一个函数,该函数计算页面加载中SQL查询的数量
In the child class which extends the parent class, after every: mysql_query($query);
在扩展父类的子类中,每次之后: mysql_query($query);
I put parent::update_query_function();
我把parent::update_query_function();
where update_query_function()
is: 其中update_query_function()
为:
function update_query_function(){
$this->query_num++;
}
the $query_num
variable in the parent class is not being updated. 父类中的$query_num
变量未更新。 Why? 为什么?
If your child class extends the parent class there's no need to do that, do this instead: 如果您的子类扩展了父类,则无需这样做,而是这样做:
$this->update_query_function();
that's the point of inheritance. 这就是继承的重点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.