Smoking Sheriff
Smoking Sheriff

Reputation: 471

How to call a non static method of parent class form static method of child class in PHP

How can i call a non static method of parent class form static method of child class in PHP? Please help.

 public static function countryArray(){
    $sql = "SELECT `country_id`, `country_name` FROM `dr_tbl_country`";
    $resultSet  = parent::dBQueryExecute($sql);
    if(mysql_num_rows($resultSet) > 0){
        $countryArray = array();
        while($result = mysql_fetch_array($resultSet)){
            extract($result);
            $countryArray[$country_id]['country_id'] = $country_id;
            $countryArray[$country_id]['country_name'] = $country_name;
        }
        return $countryArray;       
    }else{
        return false;
    }
}

Upvotes: 3

Views: 1349

Answers (3)

Ben Carey
Ben Carey

Reputation: 16958

In short, you can't

You are not able to call a non-static method of a parent class from a static method of a child class.

Your best option is to make the method non-static

Upvotes: 1

NawaMan
NawaMan

Reputation: 25687

I am pretty sure that you can't call non-static method from static method (no matter parent or child). That because there is no way to know what instance the non-static method should be called on .... from with in the static method. This should be true for all OOP languages.

Upvotes: 1

alex
alex

Reputation: 490263

You can't; static items work with other static items.

Upvotes: 2

Related Questions