簡體   English   中英

如何在PHP中從子類的靜態方法調用父類的非靜態方法

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

如何在PHP中從子類的靜態方法調用父類的非靜態方法? 請幫忙。

 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;
    }
}

你不能 靜態項目與其他靜態項目一起使用。

我非常確定您不能從靜態方法(無論父級還是子級)中調用非靜態方法。 那是因為沒有辦法知道應該在靜態方法中從...調用非靜態方法的實例。 所有OOP語言都應該如此。

簡而言之, 你不能

您不能從子類的static方法中調用父類的非static方法。

最好的選擇是使方法為非static

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM