时间:2021-07-01 10:21:17 帮助过:21人阅读
class Name extends Another Class
{
Access Variable Declaration
Access Function Declaration
}
//定义一个跟踪用户的类
class User
{
//属性
public $name;
private $password, $lastLogin;
//方法
public function __construct($name, $password)
{
$this->name = $name;
$this->password = $password;
$this->lastLogin = time();
$this->accesses ;
}
// 获取最后访问的时间
function getLastLogin()
{
return(date("M d Y", $this->lastLogin));
}
}
//创建一个对象的实例
$user = new User("Leon", "sdf123");
//获取最后访问的时间
print($user->getLastLogin() ."
n");
//打印用户名
print("$user->name n");
?>
//组件
class Widget
{
public $name='none';
public $created=FALSE;
}
//装配器
class Assembler
{
public function make(Widget $w)
{
print("Making $w->name
n");
$w->created=TRUE;
}
}
//建立一个组件对象
$thing = new Widget;
$thing->name = 'Gadget';
//装配组件
Assembler::make($thing);
?>