批改状态:合格
老师批语:
<?php
/**
* Created by PhpStorm.
* User: 金超
* Date: 2018/5/3
* Time: 15:43
*/
namespace movieInfo;
class MovieList{
private $name='';
private $size='0 byte';
private $CreationDate='0000-00-00';
private $charge=[];
private $data=[];
//构造
public function __construct($name='',$size='',$CreationDate='',array $charge=[])
{
$this->name=$name;
$this->size=$size;
$this->CreationDate=$CreationDate;
$this->charge=$charge;
}
//查询器
public function __get($name)
{
$warning=null;
if(isset($this->$name)){
$warning=$this->$name;
}elseif(isset($this->data[$name])){
$warning=$this->data[$name];
}else{
$warning='未查到该属性';
}
return $warning;
}
//设置器
public function __set($name, $value)
{
if(isset($this->$name)){
$this->$name=$value;
}else{
$this->data[$name]=$value;
}
// TODO: Implement __set() method.
}
}点击 "运行实例" 按钮查看在线实例
测试函数
<?php
require 'class/movielist.php';
$movielist=@new \movieInfo\MovieList('碟中谍','199,121,254 byte','2016-04-27',['no',0]);
echo'影片名:'.$movielist->name.'<br>';
echo'影片大小:'.$movielist->size.'<br>';
echo'更新日期:'.$movielist->CreationDate.'<br>';
echo'是否收费:'.print_r($movielist->charge[0],true).'费用:'.print_r($movielist->charge[1],true).'元'.'<br>';
echo'<hr style="color:orangered">';
//测试__set()
$movielist->name='泰坦尼克号';
$movielist->size='279,316,484 byte';
$movielist->CreationDate='1998-02-15';
$movielist->charge=['yes','$25'];
echo'影片名:'.$movielist->name.'<br>';
echo'影片大小:'.$movielist->size.'<br>';
echo'更新日期:'.$movielist->CreationDate.'<br>';
echo'是否收费:'.print_r($movielist->charge[0],true).'费用:'.print_r($movielist->charge[1],true).'元'.'<br>';
echo'<hr style="color:#7a43b6">';
//用户自定义属性
$movielist->reward='第70届奥斯卡金像奖';
$movielist->link='http://www.iqiyi.com/v_19rrny4w8w.html';
$link=$movielist->link;
echo'获奖:'.$movielist->reward.'<br>';
echo'观看地址:'."<a href={$link} title=''>".$movielist->link.'<br>';点击 "运行实例" 按钮查看在线实例
测试结果

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号