<?php
//重写父类中的成员属性
//天气基类
class WeatherBase{
protected $country="中国";
protected $city="广州市";
protected $temperature=16;
protected $weather;
}
?>
<?php
class sonWeather extends WeatherBase{
public function Forecast(){
$this->country="北京";
$this->temperature=3;
$this->weather="多云";
//返回数组
return array(
"title"=>"天气预报",
"city"=>$this->country,
"temperature"=>$this->temperature,
"weather"=>$this->weather,
);
}
}
//调用
$class=new sonWeather();
$rows=$class->Forecast();
//输出数组数据
var_dump($rows);
//
// 输出:
//array (size=4)
// 'title' => string '天气预报' (length=8)
// 'city' => string '北京' (length=4)
// 'temperature' => int 3
// 'weather' => string '多云' (length=4)
?>