Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
<?php
namespace _0815;
class Zuoye {
public function __construct($name)
{
$this->name = $name;
}
}
class Name extends Zuoye
{
public function __construct($name,$age)
{
parent::__construct($name);
$this->age = $age;
}
public function getOut(){
return $this->name .'同学,年龄'. $this->age.'岁';
}
}
echo "1. 实例演示类的扩展,抽象,接口的语法<br/>";
echo "类的扩展<br/>";
$res = new Name( '小明',18);
echo $res->getOut();
echo "<br/>";
abstract class Myname
{
public string $name = 'kiraer';
abstract public function getName($name);
}
class Mz extends Myname
{
public function getName($name)
{
return $name.'同学你好';
}
}
echo "类的抽象<br/>";
$my = new Mz();
echo $my->getName($my->name);
echo "<br/>";
interface iNickname
{
public function getMyname($name);
public function getMYage($age);
}
class Web implements iNickname
{
public function getMyname($name)
{
return '你好'.$name.'同学';
}
public function getMYage($age)
{
return '今年'.$age.'岁';
}
}
echo "接口<br/>";
$name = new Web();
echo $name->getMyname('小王').','. $name->getMYage('15');
echo "<br/>";
<?php
namespace _0815_1;
echo "2. 全局成员有哪些,他们有哪些特点?为什么要用命名空间, 描述命名空间的作用,以及声明方式, 跨空间成员的访问方式";
echo "<br/>";
echo "全局成员有函数,常量,类/接口,全局都可以用,但是不能重复";
echo "<br/>";
echo "描述命名空间的作用,可以解决全局成员重复的问题";
echo "<br/>";
class One
{
public function show(){
return __METHOD__;
}
}
$res = new One();
echo $res->show();
echo "<br/>";
namespace _0815_2;
class One
{
public function show(){
return __METHOD__;
}
}
$res = new One();
echo $res->show();
echo "<br/>";
namespace _0815_3;
class One
{
public function show(){
return __METHOD__;
}
}
namespace _0815_4;
class One
{
public function show(){
return __METHOD__;
}
}
echo "跨空间成员的访问方式";
echo "<br/>";
use _0815_3\One as one_index;
$res_one =new one_index();
echo $res_one->show();