Mazatec
Mazatec

Reputation: 11649

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

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

I put parent::update_query_function();

where update_query_function() is:

function update_query_function(){

$this->query_num++;

}

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

Upvotes: 1

Views: 1235

Answers (1)

Gal
Gal

Reputation: 23662

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.

Upvotes: 1

Related Questions