扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
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); ?> |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。