您的位置:首页 > 其它

重写父类中的成员属性

2015-10-11 09:43 232 查看
<?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)

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: