[英]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.