Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:好
<?php
abstract class CreateInstance
{
}
class User1 extends CreateInstance
{
// 创建类的实例
public static function create() : self
{
return new self();
}
}
class User2 extends CreateInstance
{
// 创建类的实例
public static function create() : self
{
return new self();
}
}
// 生成User1实例
$user1 = User1::create();
var_dump($user);
echo "<hr>";
// 生成User2实例
$user2 = User2::create();
var_dump($user2);
<?php
// static后期静态绑定
abstract class CreateInstance
{
public static $name;
public static $age;
// 创建类的实例
public static function show()
{
return '姓名:'. static::$name . ',年龄:' .static::$age;
}
}
class User1 extends CreateInstance
{
public static $name='小芳';
public static $age='20';
}
class User2 extends CreateInstance
{
public static $name='小李';
public static $age='21';
}
// 生成User1实例
echo User1::show();
echo "<hr>";
// 生成User2实例
echo User2::show();