批改状态:未批改
老师批语:

<?php
class Person {
private $name = '';
private $sex = '';
private $old = 0;
private $martical = '';
public function __construct($name, $sex, $old, $martical) {
$this->name = $name;
$this->sex = $sex;
$this->old = $old;
$this->martical = $martical;
}
public function show() {
echo '<b>姓名:</b> ' . $this->name . ' ' . '<b>性别:</b> ' . $this->sex . ' ' . '<b>年纪:</b> ' . $this->old . ' ' . '<b>武功:</b> ' . $this->martical;
}
public function __set($name, $value) {
$this->$name = $value;
}
public function __get($name) {
return $this->$name;
}
}
$wxb = new Person('韦小宝', '男', '20', '三寸不烂之舌');
$wxb->show();
echo '<hr>';
$qf = new Person('乔峰', '男', '30', '降龙十八掌');
$qf->show();
echo '<hr>';
$zwj = new Person('张无忌', '男', '25', '九阳神功');
$zwj->show();
echo '<hr>';
$xz = new Person('虚竹', '男', '22', '北冥神功');
$xz->show();
echo '<hr>';
$yg = new Person('杨过', '男', '24', '九阴真经');
$yg->show();
$yg->martical = '除了九阴真经还有自创的黯然消魂掌';
echo '<hr>';
$yg->show();点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号