Correction status:qualified
Teacher's comments:
class/Computer.php
<?php /** * Created by PhpStorm. * User: 清雨 * Date: 2018/5/4 * Time: 8:28 */ class Computer { protected $brand; protected $model; protected $size; public function __construct($brand, $model,$size) { $this -> brand = $brand; $this -> model = $model; $this -> size = $size; } public function game() { return '玩吃鸡游戏'; } }
点击 "运行实例" 按钮查看在线实例
Specifications.php 继承Computer.php
class/Specifications.php
<?php /** * Created by PhpStorm. * User: 清雨 * Date: 2018/5/4 * Time: 8:57 */ class Specifications extends Computer { public function __get($name) { return $this -> $name; } private $specifications; private $price; public function __construct($brand, $model, $size, $specifications, $price) { parent::__construct($brand, $model, $size); $this ->specifications = $specifications; $this ->price = $price; } }
点击 "运行实例" 按钮查看在线实例
index.php
<?php /** * Created by PhpStorm. * User: 清雨 * Date: 2018/5/4 * Time: 9:01 */ spl_autoload_register(function ($className){ require './class/'.$className.'.php'; }); $specifications = new Specifications('联想','拯救者R720','15','笔记本电脑','6099'); echo '品牌:'.$specifications ->brand.'<br>'; echo '型号:'.$specifications ->model.'<br>'; echo '尺寸:'.$specifications ->size.'<br>'; echo '价格:'.$specifications ->price.'<br>'; echo '类型:'.$specifications ->specifications.'<br>'; echo '<hr>'; echo '能玩什么游戏:'.$specifications ->game().'<br>';
点击 "运行实例" 按钮查看在线实例