<?php /** * Created by PhpStorm. * User: czg * Date: 2016/11/29 * Time: 13:43 */ class Person { /* * 定义属性 */ public $alias; public $companyName; public $wechatVersion; public $Imei; public $uin; public $firstUseTime; public $isBuy; public $isWechatLogin; public $userDesc; /* * 定义构造函数 :实例化是会被调用 */ function __construct($alias, $companyName, $wechatVersion, $Imei, $uin, $firstUseTime, $isBuy, $isWechatLogin, $userDesc) { echo '构造函数被调用'."<br>"; $this->$alias = $alias; $this->$companyName = $companyName; $this->$wechatVersion = $wechatVersion; $this->$Imei = $Imei; $this->$uin = $uin; $this->$firstUseTime = $firstUseTime; $this->$isBuy = $isBuy; $this->$isWechatLogin = $isWechatLogin; $this->$userDesc = $userDesc; } /* * 实例=null时或页面结束会被调用 */ function __destruct() { echo '析构函数被调用<br>'; } /* * 定义方法 */ public function add() { echo 'adding Person<br>'; } public function edit() { echo 'editting Person<br>'; } public function delete() { echo 'del Person<br>'; } } /** * 类实例化 */ $caizhigui = new Person('caizhigui', "Palmv", "6.3.28", "864394011742121", "wx864394011742121", "2016-11-30", true, true, "caizhigui by plugin in 2016-11-30"); /** * 类成员属性、方法的引用,构造函数、析构函数被调用 */ echo $caizhigui->alias; $caizhigui->add(); $caizhigui->delete();
php面向对象简单实例
最新推荐文章于 2021-04-10 12:03:48 发布