Correction status:qualified
Teacher's comments:
<?php /** * Created by PhpStorm. * User: Administrator * Date: 2018/5/8 0008 * Time: 上午 11:51 */ class Computer { private $age; private $color; public function __construct() { } public function Internet($name) { echo $name."上网设备<br>"; } /** * @return mixed */ public function getAge() { return $this->age; } /** * @return mixed */ public function getColor() { return $this->color; } }
点击 "运行实例" 按钮查看在线实例
<?php /** * Created by PhpStorm. * User: Administrator * Date: 2018/5/8 0008 * Time: 上午 11:54 */ Trait littleCompuer { private $name; private $age; private $use; public function Sell($name){ return $this->name = $name; } // public function Internet($name){ // echo $name."上网办公设备<br>"; // } }
点击 "运行实例" 按钮查看在线实例
<?php /** * Created by PhpStorm. * User: Administrator * Date: 2018/5/8 0008 * Time: 上午 11:56 */ header("content-type:text/html;charset=utf-8"); require_once "class/Computer.php"; require_once "Trait/littleCompuer.php"; class ThinkPad extends Computer { use littleCompuer; public function __construct() { } // public function Internet($name) // { //// parent::Internet($name); // TODO: Change the autogenerated stub // echo $name."用来上网办公<br>"; // } public function getAge() { return parent::getAge(); // TODO: Change the autogenerated stub } public function getColor() { return parent::getColor(); // TODO: Change the autogenerated stub } } $thinkPag = new ThinkPad(); //echo $thinkPag->Internet("ThinkPad");//如果 ThinkPad 子类同时extend Computer use Trait 并且 自身重载了Internet方法 那么以自身方法输出结果为准,参数不能缺 //echo $thinkPag->Internet("小型");//如果ThinkPad子类没有重载Internet方法那么往上一级Train寻找,如果有该方法以Trait为准 进行输出 echo $thinkPag->Internet("Computer");//如果子类 本身 Trait 均没有此方法,再向上一级寻找 也就是 Computer寻找 以父类输出为准
点击 "运行实例" 按钮查看在线实例